• 利用DES,C#加密,Java解密代码


      //C#加密
      /// <summary>
            /// 进行DES加密。
            /// </summary>
            /// <param name="pToEncrypt">要加密的字符串。</param>
            /// <param name="sKey">密钥,且必须为8位。</param>
            /// <returns>以Base64格式返回的加密字符串。</returns>
              public static string Encode(string str)  
            {
                string keyXml = CommonMethor.GetEncrptKeyByRpt(Contant.contantUrl+"api/sys/getEncrptKey");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(keyXml);
                XmlNode root = doc.SelectSingleNode("string");//当节点Workflow带有属性是,使用SelectSingleNode无法读取 
    
                string key = root.LastChild.InnerText;
                DESCryptoServiceProvider provider = new DESCryptoServiceProvider();  
                provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));  
                provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));  
                byte[] bytes = Encoding.GetEncoding("UTF-8").GetBytes(str);  
                MemoryStream stream = new MemoryStream();  
                CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);  
                stream2.Write(bytes, 0, bytes.Length);  
                stream2.FlushFinalBlock();  
                StringBuilder builder = new StringBuilder();  
                foreach (byte num in stream.ToArray())  
                {  
                    builder.AppendFormat("{0:X2}", num);  
                }  
                stream.Close();  
                return builder.ToString();  
                }
                
                
    java解密
    
    public static void main(String[] args) {
    //        String decryptToken = null;
    //        String key = "JM@XBCRM";
    //        String token = "C36B90D474184911EE21D4330730847E50F34F57DB92D38AA083AA66064F658C";
    //        try
    //        {
    //            decryptToken = ClientUtils.decrypt(token,key);
    //            decryptToken = java.net.URLDecoder.decode(decryptToken, "utf-8");
    //            System.out.println("加密串为[" + token + "],解密后为[" + decryptToken + "]");
    //        } catch (Exception e)
    //        {
    //            e.printStackTrace();
    //        }
        }

     原创文章如转载,请注明出处

  • 相关阅读:
    C语言volatile
    2017-10-12 下一步计划
    关于步进电机的半流设置、衰减设置
    压力校准仪开发-----步进电机驱动
    kei中实现在线仿真看波形
    42步进电机与57步进电机
    网上的说TB6560存在的问题
    TB6560步进电机驱动板
    继承
    iOS设计模式——单例模式
  • 原文地址:https://www.cnblogs.com/pongyc/p/7514536.html
Copyright © 2020-2023  润新知