コード例 #1
0
ファイル: RsaEncryption.cs プロジェクト: KacheTech/EasyCrypto
        /// <summary>
        /// Decrypts array of bytes (if public key is used for encryption than private key needs to be used for decryption and vice versa)
        /// </summary>
        /// <param name="data">Data to decrypt</param>
        /// <param name="key">Key to use for decryption</param>
        /// <returns>Decrypted data</returns>
        public static byte[] Decrypt(byte[] data, RsaPrivateKey key)
        {
            using (var rsa = RSA.Create())
            {
                var parms = key.GetParameters();
                rsa.KeySize = parms.Modulus.Length * 8;
                rsa.ImportParameters(parms);

                return(rsa.Decrypt(data, RSAEncryptionPadding.OaepSHA1));
            }
        }
コード例 #2
0
ファイル: RsaEncryption.cs プロジェクト: KacheTech/EasyCrypto
 /// <summary>
 /// Decrypts string (if public key is used for encryption than private key needs to be used for decryption and vice versa)
 /// </summary>
 /// <param name="data">Data to decrypt</param>
 /// <param name="key">Key to use for decryption</param>
 /// <returns>Decrypted data</returns>
 public static string Decrypt(string data, RsaPrivateKey key)
 {
     byte[] bytes     = Convert.FromBase64String(data.UglifyBase64());
     byte[] decrypted = Decrypt(bytes, key);
     return(Encoding.UTF8.GetString(decrypted));
 }
コード例 #3
0
ファイル: RsaKeyPair.cs プロジェクト: KacheTech/EasyCrypto
 /// <summary>
 /// Constructor, accepts RSAParameters
 /// </summary>
 /// <param name="rsaParams">RSA parameters</param>
 public RsaKeyPair(RSAParameters rsaParams)
 {
     PublicKey  = new RsaPublicKey(rsaParams);
     PrivateKey = new RsaPrivateKey(rsaParams);
 }
コード例 #4
0
 /// <summary>
 /// Constructor accepts private key, only stores public part of the key
 /// </summary>
 /// <param name="key">Private key</param>
 public RsaPublicKey(RsaPrivateKey key) : this(key?.Key)
 {
 }
コード例 #5
0
ファイル: RsaKeyPair.cs プロジェクト: KacheTech/EasyCrypto
 /// <summary>
 /// Constructor accepts private key
 /// </summary>
 /// <param name="privateKey">Private key</param>
 public RsaKeyPair(RsaPrivateKey privateKey)
 {
     PrivateKey = privateKey ?? throw new System.ArgumentNullException(nameof(privateKey));
     PublicKey  = new RsaPublicKey(privateKey);
 }