Vaibhav Srivastava
Vaibhav Srivastava

Reputation: 43

How to set Encryption Mode for PGPCore encryption method

I was working on PGP core encryption/decryption. It is working fine and I am using AES 256 algorithm to encrypt data. but AES: Default is CBC. I was looking for to set mode as "CTR" for encryption but but did not find any way. Below is my code for encrypting the data.

 private static void EncryptFile(string inputFile, string outputFile, string publicKeyPath) {
 using (Stream outputStream = File.Create(outputFile))
 using (Stream inputStream = File.OpenRead(inputFile))
 using (Stream publicKeyStream = File.OpenRead(publicKeyPath))
 {
     PgpPublicKey publicKey = ReadPublicKey(publicKeyStream);

     PgpEncryptedDataGenerator encryptedDataGen = new PgpEncryptedDataGenerator(SymmetricKeyAlgorithmTag.Aes256, true, new SecureRandom());
    
     encryptedDataGen.AddMethod(publicKey);
     using (Stream compressedDataStream = encryptedDataGen.Open(outputStream, new byte[4096]))
     using (Stream compressedData = new PgpCompressedDataGenerator(CompressionAlgorithmTag.Zip).Open(compressedDataStream))
     {
         inputStream.CopyTo(compressedData);
     }

 }

}

Can you please help me to find the way like how to do it?

Thanks In Advance

Upvotes: 0

Views: 174

Answers (0)

Related Questions