コード例 #1
0
        public static async Task <string> DecryptRSATextToTextAsync(string text, string privateKey, string passphrase)
        {
            byte[]       byteArrayText1   = Encoding.UTF8.GetBytes(text);
            MemoryStream encMemoryStream1 = new MemoryStream(byteArrayText1);

            byte[]       byteArrayPrvKey = Encoding.UTF8.GetBytes(privateKey);
            MemoryStream streamPrv       = new MemoryStream(byteArrayPrvKey);

            var streamDecOut = new MemoryStream();

            using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt())
            {
                await pgp.DecryptAsync(encMemoryStream1, streamDecOut, streamPrv, passphrase);
            }

            byte[] decryptedBytes = streamDecOut.ToArray();
            var    decryptedText  = Encoding.UTF8.GetString(decryptedBytes);

            return(decryptedText);
        }