Exemplo n.º 1
0
        public static ICryptoValue Decrypt(string cipherText, string pwd, CipherTextTypes cipherTextType, Encoding encoding = null, Func <string, byte[]> customConverter = null)
        {
            encoding = encoding.SafeEncodingValue();
            var key      = Factory.GenerateKey(pwd, encoding);
            var function = Factory.Create(RcTypes.RC4, key);

            return(function.Decrypt(cipherText, cipherTextType, encoding, customConverter));
        }
        public ICryptoValue DecryptByPublicKey(string cipherText, CipherTextTypes cipherTextType, Encoding encoding, CancellationToken cancellationToken, Func <string, byte[]> customCipherTextConverter = null)
        {
            encoding = encoding.SafeEncodingValue();

            var finalCipherText = cipherTextType.GetBytes(cipherText, encoding, customCipherTextConverter);

            return(DecryptByPublicKey(finalCipherText, cancellationToken));
        }
        public ICryptoValue Decrypt(string cipherText, string salt, CipherTextTypes cipherTextType, Encoding encoding, CancellationToken cancellationToken, Func <string, byte[]> customCipherTextConverter = null)
        {
            encoding = encoding.SafeEncodingValue();

            var finalCipherText = cipherTextType.GetBytes(cipherText, encoding, customCipherTextConverter);

            var saltBytes = string.IsNullOrWhiteSpace(salt) ? new byte[0] : encoding.GetBytes(salt);

            return(Decrypt(finalCipherText, saltBytes, cancellationToken));
        }
Exemplo n.º 4
0
        public static byte[] GetBytes(this CipherTextTypes signatureTextType, string signature, Encoding encoding = default, Func <string, byte[]> customCipherTextConverter = null)
        {
            encoding = encoding.SafeEncodingValue();

            return(signatureTextType switch
            {
                CipherTextTypes.PlainText => encoding.GetBytes(signature),
                CipherTextTypes.Base32Text => BaseConv.FromBase32(signature),
                CipherTextTypes.Base64Text => BaseConv.FromBase64(signature),
                CipherTextTypes.Base91Text => BaseConv.FromBase91(signature),
                CipherTextTypes.Base256Text => BaseConv.FromBase256(signature),
                CipherTextTypes.ZBase32Text => BaseConv.FromZBase32(signature),
                CipherTextTypes.Hex => Org.BouncyCastle.Utilities.Encoders.Hex.Decode(signature),
                _ => customCipherTextConverter is null?encoding.GetBytes(signature) : customCipherTextConverter(signature)
            });
 public ICryptoValue DecryptByPublicKey(string cipherText, CipherTextTypes cipherTextType, CancellationToken cancellationToken, Func <string, byte[]> customCipherTextConverter = null)
 {
     return(DecryptByPublicKey(cipherText, cipherTextType, Encoding.UTF8, cancellationToken, customCipherTextConverter));
 }
 public ICryptoValue DecryptByPrivateKey(string cipherText, CipherTextTypes cipherTextType, Encoding encoding, CancellationToken cancellationToken, Func <string, byte[]> customCipherTextConverter = null)
 {
     return(DecryptByPrivateKey(cipherText, cipherTextType, RSAEncryptionPadding.Pkcs1, encoding, cancellationToken, customCipherTextConverter));
 }
 public ICryptoValue DecryptByPublicKey(string cipherText, CipherTextTypes cipherTextType, RSAEncryptionPadding padding, Encoding encoding = null, Func <string, byte[]> customCipherTextConverter = null)
 {
     return(DecryptByPublicKey(cipherText, cipherTextType, padding, encoding, CancellationToken.None, customCipherTextConverter));
 }
 public ICryptoValue DecryptByPrivateKey(string cipherText, CipherTextTypes cipherTextType, bool fOEAP, Encoding encoding = null, Func <string, byte[]> customCipherTextConverter = null)
 {
     return(DecryptByPrivateKey(cipherText, cipherTextType, fOEAP, encoding, CancellationToken.None, customCipherTextConverter));
 }
 public ICryptoValue Decrypt(string cipherText, string salt, CipherTextTypes cipherTextType, Encoding encoding = null, Func <string, byte[]> customCipherTextConverter = null)
 {
     return(Decrypt(cipherText, salt, cipherTextType, encoding, CancellationToken.None, customCipherTextConverter));
 }