没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
C#的直接DES-CBC加密跟openssl的DES-CBC结果不一样,原因是因为数据填充问题
直接调用dllimport会有指针问题。。很容易内存挂掉。。
转换后的数组填充方式 byte[] data = new byte[字符串长度+1]
注:是字符串长度+1 不是byte[]的长度+1
研究发现openssl 这个不知道为啥要从第1个字节填充,比如
字符串 "A"
字节组 byte[] data = new data["A".length*2+1];
转后unicode后字节组填充
字节组的值默认是 00 00 00
从第一个字节填充 00 00 41
我调试时用的key
byte[] key = new byte[8] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
public static byte[] Encrypt(string input, byte[] key)
{
using (DES des_cbc = new DESCryptoServiceProvider())
{
des_cbc.Mode = CipherMode.CBC;
//Key必须是8位字节
des_cbc.Key = key;
//因为cbc模式不需要iv偏移,所以直接声明为 8个0x00;
des_cbc.IV =new byte[8] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
直接调用dllimport会有指针问题。。很容易内存挂掉。。
转换后的数组填充方式 byte[] data = new byte[字符串长度+1]
注:是字符串长度+1 不是byte[]的长度+1
研究发现openssl 这个不知道为啥要从第1个字节填充,比如
字符串 "A"
字节组 byte[] data = new data["A".length*2+1];
转后unicode后字节组填充
字节组的值默认是 00 00 00
从第一个字节填充 00 00 41
我调试时用的key
byte[] key = new byte[8] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
public static byte[] Encrypt(string input, byte[] key)
{
using (DES des_cbc = new DESCryptoServiceProvider())
{
des_cbc.Mode = CipherMode.CBC;
//Key必须是8位字节
des_cbc.Key = key;
//因为cbc模式不需要iv偏移,所以直接声明为 8个0x00;
des_cbc.IV =new byte[8] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
资源评论
sin9527
- 粉丝: 2
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功