예제 #1
0
        public static string RsaDecryptHex(string text, string privateKey)
        {
            try
            {
                using (RSACryptoServiceProvider crypto = new RSACryptoServiceProvider(1024))
                {
                    crypto.FromXmlString(privateKey);

                    byte[] bytes   = ConvertUtil.HexStringToBytes(text);
                    byte[] results = crypto.Decrypt(bytes, true);

                    return(Encoding.UTF8.GetString(results));
                }
            }
            catch
            {
                return(null);
            }
        }
예제 #2
0
        public static string AesDecryptHex(string text, string key)
        {
            try
            {
                using (RijndaelManaged rm = new RijndaelManaged())
                {
                    rm.Key     = Encoding.UTF8.GetBytes(key);
                    rm.Mode    = CipherMode.ECB;
                    rm.Padding = PaddingMode.PKCS7;

                    using (ICryptoTransform cTransform = rm.CreateDecryptor())
                    {
                        byte[] bytes   = ConvertUtil.HexStringToBytes(text);
                        byte[] results = cTransform.TransformFinalBlock(bytes, 0, bytes.Length);

                        return(Encoding.UTF8.GetString(results));
                    }
                }
            }
            catch
            {
                return(null);
            }
        }