Exemplo n.º 1
0
        /// <summary>
        /// 3DES解密
        /// </summary>
        /// <param name="pKey">解密密钥</param>
        /// <param name="pDecryptContent">需要解密的内容</param>
        /// <returns></returns>
        public static byte[] TripleDESDecrypt(string pKey, string pDecryptContent)
        {
            byte[] keyBytes     = Encoding.UTF8.GetBytes(pKey);
            byte[] contentBytes = Encoding.UTF8.GetBytes(pDecryptContent);

            return(EncDecUtil.TripleDESDecrypt(keyBytes, contentBytes));
        }
Exemplo n.º 2
0
 /// <summary>
 /// RSA加密
 /// </summary>
 /// <param name="pCertFilePath">pfx证书文件路径</param>
 /// <param name="pCertFilePassword">pfx证书文件的密码</param>
 /// <param name="pEncryptContent">需要加密的内容</param>
 /// <returns>密文</returns>
 public static byte[] RSAEncrypt(string pCertFilePath, string pCertFilePassword, string pEncryptContent)
 {
     using (FileStream fs = new FileStream(pCertFilePath, FileMode.Open))
     {
         byte[] bytes = new byte[fs.Length];
         fs.Read(bytes, 0, bytes.Length);
         fs.Close();
         X509Certificate2 mycert = new X509Certificate2(bytes, pCertFilePassword,
                                                        X509KeyStorageFlags.MachineKeySet
                                                        | X509KeyStorageFlags.PersistKeySet
                                                        | X509KeyStorageFlags.Exportable);
         AsymmetricKeyParameter bouncyCastlePrivateKey = EncDecUtil.TransformRSAPrivateKey(mycert.PrivateKey);
         IBufferedCipher        c = CipherUtilities.GetCipher("RSA/ECB/PKCS1Padding");// 参数与JAVA中解密的参数一致
         c.Init(true, bouncyCastlePrivateKey);
         byte[] outBytes = c.DoFinal(Encoding.UTF8.GetBytes(pEncryptContent));
         return(outBytes);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 按Java的方式对源字符串进行MD5加密
 /// </summary>
 /// <param name="pSource"></param>
 /// <returns></returns>
 public static string MD5ForJava(string pSource)
 {
     return(EncDecUtil.MD5ForJava(Encoding.UTF8.GetBytes(pSource)));
 }
Exemplo n.º 4
0
 /// <summary>
 /// 3DES加密
 /// </summary>
 /// <param name="pKey">加密密钥</param>
 /// <param name="pEncryptContent">需要加密的内容</param>
 /// <returns></returns>
 public static byte[] TripleDESEncrypt(string pKey, byte[] pEncryptContent)
 {
     byte[] keyBytes = Encoding.UTF8.GetBytes(pKey);
     return(EncDecUtil.TripleDESEncrypt(keyBytes, pEncryptContent));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Base64加密
 /// </summary>
 /// <param name="pEncryptContent">需要进行Base64加密的字符串(字符串以UTF-8编码)</param>
 /// <returns></returns>
 public static string Base64Encrypt(string pEncryptContent)
 {
     return(EncDecUtil.Base64Encrypt(Encoding.UTF8.GetBytes(pEncryptContent)));
 }