コード例 #1
0
        public static byte[] Decrypt(byte[] data, string keysPair)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (keysPair == null)
            {
                throw new ArgumentNullException(nameof(keysPair));
            }

            CryptoHelper.Separate(out var encryptedKey, out var encryptedData, data, AsymmetricEncryption.KeySize);

            var commonKey = AsymmetricEncryption.Decrypt(encryptedKey, keysPair);

            return(SymmetricEncryption.Decrypt(encryptedData, commonKey));
        }
コード例 #2
0
        public static void Decrypt(Stream input, Stream output, string keysPair)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }
            if (keysPair == null)
            {
                throw new ArgumentNullException(nameof(keysPair));
            }

            var encryptedKey = new byte[AsymmetricEncryption.KeySize];

            input.Read(encryptedKey, 0, encryptedKey.Length);

            var commonKey = AsymmetricEncryption.Decrypt(encryptedKey, keysPair);

            SymmetricEncryption.Decrypt(input, output, commonKey);
        }