Click here to Skip to main content
15,438,113 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am getting exception while passing a long string to save to the windows vault folder using c# and Credential Manager API. Else it is getting saved successfully to the vault.

Exception coming is
Specified argument was out of the range of valid values.

Parameter name: The password has exceeded 512 bytes.


What I have tried:

public void SavePassword(string password)
               using (var cred = new Credential())
                   cred.Password = password;
                   cred.Target = PasswordName;
                   cred.Type = CredentialType.Generic;
                   cred.PersistanceType = PersistanceType.LocalComputer;
           catch(Exception ex)


Updated 3-Nov-21 21:44pm
GKP1992 18-May-18 7:39am    
Just me or the password string goes on and on in a single line overflowing the CP page?Chrome by the way.
Richard Deeming 18-May-18 9:40am    
It's not just you. The browser can't find an obvious place to break the line, so without word-wrap: break-word; on the containing <div>, it won't wrap onto a new line.
GKP1992 21-May-18 0:22am    
Why do you need to have such a long password anyway? Can a user ever remember that?

Parameter name: The password has exceeded 512 bytes.

Your password is 600 bytes long and the maximum allowed is 512.
Share this answer
ranio 4-Jun-18 3:11am     CRLF
So what is the solution for saving public key content length greater than 512 bytes long. Can I split the same say 500 bytes each and then save to the vault and retrieve concatenating the splited vault values altogether. Is this split option possible or Is there any better option to do the same ?

and follow these steps.
// Save the credential to the credential manager
    applicationName: "CredentialManagerTests",
    userName: "meziantou",
    secret: "Pa$$w0rd",
    comment: "Test",
    persistence: CredentialPersistence.LocalMachine);

// Get a credential from the credential manager
var cred = CredentialManager.ReadCredential(applicationName: "CredentialManagerTests");

// Delete a credential from the credential manager
CredentialManager.DeleteCredential(applicationName: "CredentialManagerTests");
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900