![simple online pgp encryption tool simple online pgp encryption tool](https://static.goanywhere.com/images/products/mft/GoAnywhereMFT_OpenPGP-Diagram.png)
PgpEncryptedDataGenerator encGen = new PgpEncryptedDataGenerator( OutputStream = new ArmoredOutputStream(outputStream) īyte bytes = PgpExampleUtilities.CompressFile(fileName, CompressionAlgorithmTag.Zip) Using (Stream output = File.Create(outputFileName))ĮncryptFile(output, inputFileName, encKey, armor, withIntegrit圜heck) PgpPublicKey encKey = PgpExampleUtilities.ReadPublicKey(encKeyFileName) The encryption part does not require the private key.Īll credits go to the original author NightBaker. If you want to do both encryption and decryption in dotnet core, this is the article I followed: Using (Stream cOut = cPk.Open(outputStream, bytes.Length)) Using (Stream cOut = cPk.Open(armoredStream, bytes.Length)) Using (ArmoredOutputStream armoredStream = new ArmoredOutputStream(outputStream)) Using (Stream outputStream = File.Create(outputFile)) PgpEncryptedDataGenerator cPk = new PgpEncryptedDataGenerator(SymmetricKeyAlgorithmTag.Aes256, PgpUtilities.WriteFileToLiteralData(comData.Open(bOut), PgpLiteralData.Binary, PgpCompressedDataGenerator comData = new PgpCompressedDataGenerator(CompressionAlgorithmTag.Zip) Using (MemoryStream bOut = new MemoryStream()) Public static void EncryptFile(string inputFile, string outputFile, PgpPublicKey encKey, bool armor, Throw new ArgumentException("Can't find encryption key in key ring.") Private PgpPublicKey getFirstPublicEncryptionKeyFromRing(PgpPublicKeyRing pkr)įoreach (PgpPublicKey k in pkr.GetPublicKeys()) PgpObjectFactory pgpFact = new PgpObjectFactory(pubArmoredStream) Var pubArmoredStream = new ArmoredInputStream(pubFis) Using (Stream pubFis = File.OpenRead(ascfilein)) Private PgpPublicKeyRing asciiPublicKeyToRing(string ascfilein) MessageBox.Show(ascfilein + " is not a public key.") TbUnencryptedFile.Text, tbEncryptedFile.Text, getFirstPublicEncryptionKeyFromRing(pkr), true, true) Var pkr = asciiPublicKeyToRing(ascfilein) I've tested encrypting and then decrypting and it runs fine :) Of course to run these codes you have to include Bounc圜astle library in your project. Return pgpLiteralDataGenerator.Open(encryptedOut, PgpLiteralData.Binary, PgpLiteralDataGenerator pgpLiteralDataGenerator = new PgpLiteralDataGenerator() Private static Stream ChainLiteralOut(Stream encryptedOut, FileInfo file) Return encryptedDataGenerator.Open(outputStream, new byte) New PgpEncryptedDataGenerator(SymmetricKeyAlgorithmTag.TripleDes,ĮncryptedDataGenerator.AddMethod(m_encryptionKeys.PublicKey) PgpEncryptedDataGenerator encryptedDataGenerator Private Stream ChainEncryptedOut(Stream outputStream) While ((length = inputFile.Read(buf, 0, buf.Length)) > 0) Private static void WriteOutput(Stream literalOut, Using (FileStream inputFile = unencryptedFileInfo.OpenRead()) Using (Stream literalOut = ChainLiteralOut(encryptedOut, unencryptedFileInfo)) Using (Stream encryptedOut = ChainEncryptedOut(outputStream)) Throw new ArgumentException("File to encrypt not found.") If (!File.Exists(unencryptedFileInfo.FullName)) Throw new ArgumentNullException("unencryptedFileInfo", "unencryptedFileInfo is null.") Throw new ArgumentNullException("outputStream", "outputStream is null.") Public void Encrypt(Stream outputStream, FileInfo unencryptedFileInfo) / encrypted data when this method returns. / write the encrypted content to outputStream. / Encrypt and sign the file pointed to by unencryptedFileInfo and Throw new ArgumentNullException("encryptionKeys", "encryptionKeys is null.") Public PgpEncrypt(PgpEncryptionKeys encryptionKeys) / Instantiate a new PgpEncrypt class with initialized PgpEncryptionKeys. Private PgpEncryptionKeys m_encryptionKeys Belows is the modified codes, all the credits for the author - Mr. However I've modified the codes a bit to only require public key (no signing, no compress) and thought I should publish it here in case anyone also looking for a solution for this question. I found a tutorial here but it requires both Secret Key and Public Key to encrypt data.