public override void Encode(IBcpgOutputStream pOut) { var pk = new SymmetricKeyEncSessionPacket( EncAlgorithm, _s2K, SessionInfo); pOut.WritePacket(pk); }
internal PgpPbeEncryptedData( SymmetricKeyEncSessionPacket keyData, InputStreamPacket encData) : base(encData) { this.keyData = keyData; }
public override void Encode(BcpgOutputStream pOut) { SymmetricKeyEncSessionPacket pk = new SymmetricKeyEncSessionPacket( encAlgorithm, s2k, sessionInfo); pOut.WritePacket(pk); }
/// <summary>Return the decrypted session data for the packet.</summary> private static byte[] GetSessionData(SymmetricKeyEncSessionPacket keyData, ReadOnlySpan <byte> rawPassword) { byte[] key = Array.Empty <byte>(); try { key = new byte[PgpUtilities.GetKeySize(keyData.EncAlgorithm) / 8]; S2kBasedEncryption.MakeKey(rawPassword, keyData.S2k.HashAlgorithm, keyData.S2k.GetIV(), keyData.S2k.IterationCount, key); if (keyData.SecKeyData?.Length > 0) { using var keyCipher = PgpUtilities.GetSymmetricAlgorithm(keyData.EncAlgorithm); using var keyDecryptor = new ZeroPaddedCryptoTransform(keyCipher.CreateDecryptor(key, new byte[(keyCipher.BlockSize + 7) / 8])); return(keyDecryptor.TransformFinalBlock(keyData.SecKeyData, 0, keyData.SecKeyData.Length)); } else { var sessionData = new byte[key.Length + 1]; sessionData[0] = (byte)keyData.EncAlgorithm; key.CopyTo(sessionData, 1); return(sessionData); } } finally { CryptographicOperations.ZeroMemory(key); } }