Esempio n. 1
0
 public bool VerifyData(byte[] data, byte[] signature)
 {
     using (RSACryptoServiceProvider rsaCryptoServiceProvider = RSAContainerFactory.CreateFromPublicKey(_publicKey))
     {
         return(rsaCryptoServiceProvider.VerifyData(data, signature, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1));
     }
 }
Esempio n. 2
0
 public byte[] SignData(byte[] data)
 {
     using (RSACryptoServiceProvider rsaCryptoServiceProvider = RSAContainerFactory.CreateFromContainer(_containerName))
     {
         return(rsaCryptoServiceProvider.SignData(data, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1));
     }
 }
Esempio n. 3
0
 public byte[] DecryptData(byte[] data)
 {
     using (RSACryptoServiceProvider rsaCryptoServiceProvider = RSAContainerFactory.CreateFromContainer(_containerName))
     {
         return(rsaCryptoServiceProvider.Decrypt(data, RSAEncryptionPadding.Pkcs1));
     }
 }
Esempio n. 4
0
 public string ExportKey(bool includePrivate)
 {
     using (RSACryptoServiceProvider rsaCryptoServiceProvider = RSAContainerFactory.CreateFromContainer(_containerName))
     {
         return(rsaCryptoServiceProvider.ToXmlString(includePrivate));
     }
 }
Esempio n. 5
0
        public RSAEncryption(string containerName, string username)
        {
            _containerName = containerName;
            _username      = username;

            RSAContainerFactory.Create(containerName, username)
            .Dispose();
        }
Esempio n. 6
0
        public byte[] EncryptData(byte[] data)
        {
            if (_publicKey == null)
            {
                using (RSACryptoServiceProvider rsaCryptoServiceProvider = RSAContainerFactory.Create(_containerName, _username))
                {
                    return(rsaCryptoServiceProvider.Encrypt(data, RSAEncryptionPadding.Pkcs1));
                }
            }

            using (RSACryptoServiceProvider rsaCryptoServiceProvider = RSAContainerFactory.CreateFromPublicKey(_publicKey))
            {
                return(rsaCryptoServiceProvider.Encrypt(data, RSAEncryptionPadding.Pkcs1));
            }
        }