/// <summary> /// Decrypts the symmetric key /// </summary> /// <param name="pgpCrypt">PGP asymmetric crypting helper instance</param> /// <param name="key">The private key to decrypt the symmetric key with</param> /// <returns>The decrypted, wrapped, symmetric key contained in this packet</returns> public KeyParameter GetKey(AbstractPgpCrypt pgpCrypt, PgpPrivateKey key) { byte[] decrypted = pgpCrypt.ProcessWithLength(false, Get(0), key.Key, out int length); Array.Resize(ref decrypted, SYM_CRYPT.KeyLengthByte); if (length > SYM_CRYPT.KeyLengthByte) { throw new PgpKeyValidationException("Decryption yielded a result too large for an AES key"); } else if (length < SYM_CRYPT.KeyLengthByte) { //an error happened with leading zeros where they were put at the last place and the processed length was 15 Array.Copy(decrypted, 0, decrypted, 1, length); decrypted[0] = 0; } return(new KeyParameter(decrypted)); }
/// <summary> /// Constructs a new symmetric key packet /// </summary> public SymKeyPacket(byte specifier, KeyParameter key, AbstractPgpCrypt pgpCrypt, PgpPublicKey pgpPublicKey) : base(specifier, pgpCrypt.Encrypt(key.GetKey(), pgpPublicKey.GetKey())) { }