/// <summary> /// Encrypt the specified Password with the supplied Key /// </summary> /// <param name='Password'> /// Password to encrypt /// </param> /// <param name='Key'> /// Key for encryption /// </param> public static EncryptedPassword Encrypt(string Password, EncryptKey Key) { //Setup contracts for arguments Contract.Requires(!string.IsNullOrWhiteSpace(Password), "No password supplied!"); Contract.Requires(Key != null, "No key supplied!"); //Create instance and assign key EncryptedPassword EncryptedPassword = new EncryptedPassword (); EncryptedPassword.key = Key; //Create encryption algoritm using (RijndaelManaged AES = new RijndaelManaged()) { //Assign aes keys from the supplied key AES.Key = Key.Key; AES.IV = Key.IV; //Create encryption streams var encryptor = AES.CreateEncryptor(); using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cryptStream = new CryptoStream(ms, encryptor, CryptoStreamMode.Write)) { using (StreamWriter cryptWriter = new StreamWriter(cryptStream)) { //Write password for encryption cryptWriter.Write(Password); } //Store encrypted password EncryptedPassword.passwordData = ms.ToArray(); } } } //Return instance return EncryptedPassword; }
public LoginInfo(string Name, EncryptedPassword Password) { this.name = Name; this.password = Password; }