java desc解密_java 写的 desc 解密方法怎么用 PHP 还原

/// 解密数据

///

///

///

///

public static string Decrypt(string Text, string sKey)

{

DESCryptoServiceProvider des = new DESCryptoServiceProvider();//调一个desc的类

int len;//声明整数len的变量

len = Text.Length / 2;//把需要解密的字符长度除以2复制给len

byte[] inputByteArray = new byte[len];//声明数组长度为len 赋值给inputByteArray

int x, i;//声明整数x,i

for (x = 0; x < len; x++)

{

i = Convert.ToInt32(Text.Substring(x * 2, 2), 16);//将密码字符串每次取两位在转化成32位的符号整数 再取其16 位有符号整数的值转换为等效的 32 位有符号整数。

inputByteArray[x] = (byte)i;//把得到的符号整数 赋给数组inputByteArray

}

des.Key = ASCIIEncoding.ASCII.GetBytes

(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile

(sKey, "md5").Substring(0, 8)); //把密钥进行MD5后,取字符串0到8位

des.IV = ASCIIEncoding.ASCII.GetBytes

(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile

(sKey, "md5").Substring(0, 8));//把密钥进行MD5后,取字符串0到8位

System.IO.MemoryStream ms = new System.IO.MemoryStream();//应该也是调一个MemoryStream的类吧

CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);

//调CryptoStream类 并且传入参数 ms应该是执行的方式 des.CreateDecryptor() 用8位字符串

创建对称解密器对象 CryptoStreamMode.Write 加密

cs.Write(inputByteArray, 0, inputByteArray.Length);//上一步的结果解密后的数据放入内存流

cs.FlushFinalBlock();//用缓冲区的当前状态更新基础数据源或储存库,随后清除缓冲区。

return Encoding.UTF8.GetString(ms.ToArray());//按照UTF8的编码方式得到字符串

}

我写的解释不晓得对不对 我想问下laravel里怎么代替里面的DESCryptoServiceProvider()方法 MemoryStream()方法 CryptoStream()方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值