/// <summary>
/// Initializes a new instance of the <see cref="Cryptkeeper" /> class.
/// </summary>
/// <param name="passphrase">The encryption key or passphrase represented in a SecureString. This is the preferred method of instantiating this class because it protects the key in memory.</param>
public Cryptkeeper(System.Security.SecureString passphrase)
{
string err = "Cryptkeeper passphrase must be 16 characters (128-bit encryption) or 32 characters (256-bit) in length.";
if (passphrase == null)
{
throw new ApplicationException(err);
}
if (passphrase.Length == 0)
{
throw new ApplicationException(err);
}
if (passphrase.Length > 1 && passphrase.Length <= 16)
{
this.keysize = 128; // 128 bits is 16 bytes or 16 characters in UTF8
this.keyString = passphrase.Copy();
return;
}
if (passphrase.Length > 16 && passphrase.Length <= 32)
{
this.keysize = 256; // 256 bits is 32 bytes or 32 characters in UTF8
this.keyString = passphrase.Copy();
return;
}
if (passphrase.Length > 32)
{
throw new ApplicationException(err);
}
}