///<summary>Sets the value of the <c><PasswordList></c> element.</summary> /// <param name="Password">A representation of the user's password using the given algorithm.</param> ///<remarks> /// <para>This form of <c>setPasswordList</c> is provided as a convenience method /// that is functionally equivalent to the <c>PasswordList</c></para> /// <para>Version: 2.6</para> /// <para>Since: 2.1</para> /// </remarks> public void SetPasswordList( Password Password ) { RemoveChild( InfrastructureDTD.IDENTITY_PASSWORDLIST); AddChild( InfrastructureDTD.IDENTITY_PASSWORDLIST, new PasswordList( Password ) ); }
/// <summary> /// Returns the unencrypted password value from the /// Password field /// </summary> /// <param name="password">The field that needs to be decrypted</param> /// <returns>The unencrypted password</returns> public override string ReadPassword( Password password ) { byte [] encryptedValue = Convert.FromBase64String( password.TextValue ); byte [] iv = new byte[8]; Array.Copy( encryptedValue, 0, iv, 0, 8 ); fSymmetricAlgorithm.IV = iv; byte [] decryptedPassword; using ( ICryptoTransform decryptor = fSymmetricAlgorithm.CreateDecryptor() ) { decryptedPassword = decryptor.TransformFinalBlock ( encryptedValue, 8, encryptedValue.Length - 8 ); } return Encoding.UTF8.GetString( decryptedPassword ); }
/// <summary> /// Encrypts the specified password and populates the /// Password field with the necessary /// values /// </summary> /// <param name="password">The password object to populate</param> /// <param name="value">The value to encryp</param> public override void WritePassword( Password password, string value ) { base.WritePassword( password, value ); fSymmetricAlgorithm.GenerateIV(); byte [] source = Encoding.UTF8.GetBytes( value ); byte [] encryptedPassword; using ( ICryptoTransform encryptor = fSymmetricAlgorithm.CreateEncryptor() ) { encryptedPassword = encryptor.TransformFinalBlock( source, 0, source.Length ); } byte [] finalValue = new byte[8 + encryptedPassword.Length]; Array.Copy( fSymmetricAlgorithm.IV, 0, finalValue, 0, 8 ); Array.Copy( encryptedPassword, 0, finalValue, 8, encryptedPassword.Length ); password.TextValue = Convert.ToBase64String( finalValue ); }
/// <summary> /// Returns the password value as a Base64 string /// </summary> /// <param name="password">The field that needs to be decrypted</param> /// <returns>The unencrypted password</returns> public override string ReadPassword( Password password ) { return password.TextValue; }
/// <summary> /// Encrypts the specified password and populates the /// Password field with the necessary /// values /// </summary> /// <param name="password">The password object to populate</param> /// <param name="value">The value to encryp</param> public override void WritePassword( Password password, string value ) { base.WritePassword( password, value ); byte [] pass = Encoding.UTF8.GetBytes( value ); byte [] hashedPassword = fHashAlgorithm.ComputeHash ( pass ); password.TextValue = Convert.ToBase64String( hashedPassword ); }
/// <summary> /// Encrypts the specified password and populates the /// Password field with the necessary /// values /// </summary> /// <param name="password">The password object to populate</param> /// <param name="value">The value to encryp</param> public override void WritePassword( Password password, string value ) { base.WritePassword( password, value ); byte [] clearTextPassword = Encoding.UTF8.GetBytes( value ); password.TextValue = Convert.ToBase64String( clearTextPassword ); }
/// <summary> /// Returns the unencrypted password value from the /// Password field /// </summary> /// <param name="password">The field that needs to be decrypted</param> /// <returns>The unencrypted password</returns> public override string ReadPassword( Password password ) { byte [] clearTextPassword = Convert.FromBase64String( password.TextValue ); return Encoding.UTF8.GetString( clearTextPassword ); }
/// <summary> /// Encrypts the specified password and populates the /// Password field with the algorithm and key name /// values. This method must be overriden by the specific encryption /// algorithm to set the actual encrypted value. /// </summary> /// <param name="password">The password object to populate</param> /// <param name="value">The value to encryp</param> public virtual void WritePassword( Password password, string value ) { password.SetAlgorithm( fAlgorithm ); password.KeyName = fkeyName; }
/// <summary> /// Returns the unencrypted password value from the /// Password field. If the algorithm in use is a hash /// algorithm, the Base64 instance of the hash will be returned instead. /// </summary> /// <param name="password">The field that needs to be decrypted</param> /// <returns>The unencrypted password</returns> public abstract string ReadPassword( Password password );
/// <summary> /// Creates an instance of SIFEncryption that can decrypt /// the password field automatically, using settings /// defined in the agent's properties. /// </summary> /// <remarks> /// <para> /// This method searches the agent properties in effect /// for the zone and looks for one that matches the key /// defined in the Password object. /// If it finds one, it returns an instance of SIFEncryption /// that has been initialized with the proper key and /// encryption algorithm for the field. /// </para> /// <para> /// This method looks for a property named /// "adk.encryption.keys.[key]" where [key] is the name /// of the key field defined by the Password /// field. /// </para> /// </remarks> /// <param name="password">The password object that needs /// to be decrypted</param> /// <param name="zone">The zone that is in scope for the /// current message</param> /// <returns></returns> public static SifEncryption GetInstance( Password password, IZone zone ) { if ( sCurrentInstance != null && sCurrentInstance.Algorithm.Value == password.Algorithm && (sCurrentInstance.KeyName == password.KeyName || sCurrentInstance.Key == null) ) { return sCurrentInstance; } byte [] key = zone.Properties.GetEncryptionKey( password.KeyName ); return GetInstance( PasswordAlgorithm.Wrap( password.Algorithm ), password.KeyName, key ); }