Пример #1
0
        public static string DecryptToken(X509CertificateWrapper cert, string cipherText)
        {
            byte[] cipherBytes = null;
            if (IsHexString(cipherText))
            {
                cipherBytes = StringToByteArray(cipherText);
            }
            else
            {
                cipherBytes = Convert.FromBase64String(cipherText);
            }

            var data = AES_Decrypt(cipherBytes, cert.AESPassword, useRandomSalt: true, salt: cert.AESSalt, g1: cert.AESG1);

            return(Encoding.UTF8.GetString(data));
        }
Пример #2
0
        public static string EncryptToken(X509CertificateWrapper cert, string text, ResultType resultType = ResultType.Base64)
        {
            var data = AES_Encrypt(Encoding.UTF8.GetBytes(text), cert.AESPassword, useRandomSalt: true, salt: cert.AESSalt, g1: cert.AESG1);

            switch (resultType)
            {
            case ResultType.Hex:
                return("0x" + string.Concat(data.Select(b => b.ToString("X2"))));

            case ResultType.Base62:
                return("_" + data.ToBase62());

            default:     // base64
                return(Convert.ToBase64String(data));
            }
        }