Exemplo n.º 1
0
        public static string Decrypt(string privateKeyPath, string cipher)
        {
            var(encryptedKey, encryptedText) = Split(cipher);
            var key = RsaCryptorFactory.GetPrivateKeyCryptor(privateKeyPath)
                      .Decrypt(Convert.FromBase64String(encryptedKey), false);

            return(Aes256Cryptor.Decrypt(key, Convert.FromBase64String(encryptedText)));
        }
Exemplo n.º 2
0
        public static string Encrypt(string publicKeyPath, string text)
        {
            var key          = Aes256Cryptor.GetNewKey();
            var encryptedKey = RsaCryptorFactory.GetPublicKeyCryptor(publicKeyPath)
                               .Encrypt(key, false);
            var encryptedText = Aes256Cryptor.Encrypt(key, text);

            return(Combine(Convert.ToBase64String(encryptedKey), Convert.ToBase64String(encryptedText)));
        }