linux sha1 字符串,linux ascii到utf-16(然后sha1和base64)编码

我们有一个通信协议,要求我们对Base64编码UTF-16编码密码的SHA1哈希。我们一直在给定的Java,JavaScript和Visual Basic中的例子但是我们在Linux下运行(在redhat)linux ascii到utf-16(然后sha1和base64)编码

所提供的测试字符串:rBbBKqbJodT5awZal/CSCYF/sFo=

我已经试过

iconv_t conv = iconv_open("UTF-16LE","ASCII"); // open succeeds

char *from_string=strdup("[email protected]");

size_t from_length=strlen(from_string);

size_t to_length=from_length*3;

size_t original_to_length=to_length;

char *to_string=(char*)calloc(1,to_length);

int convert_return=iconv(conv,&from_string,&from_length,&to_string,&to_length);

// convert_return is 0 indicating success, to_length is 11, from_length is 0

运行sha1和base64编码on_string长度为22

结果输出:GCXe7HMDoq/NRqo1WWYJDDYZzP0=

如果通过to_string我环,我得到:

for (int i=0; i

printf("to_string %d = %x",i,to_string[i]);

}

output:

to_string 0 = 0

to_string 1 = 0

to_string 2 = 0

to_string 3 = 0

to_string 4 = 0

to_string 5 = 0

to_string 6 = 0

to_string 7 = 0

to_string 8 = 0

to_string 9 = 0

to_string 10 = 0

to_string 11 = 0

to_string 12 = 0

to_string 13 = 0

to_string 14 = 21

to_string 15 = 0

to_string 16 = 0

to_string 17 = 0

to_string 18 = 4

to_string 19 = 7e

to_string 20 = 13

to_string 21 = e

这里是JavaScript的转换:

function str2rstr_utf16le(input)

{

var output = "";

for(var i = 0; i < input.length; i++)

output += String.fromCharCode(input.charCodeAt(i) & 0xFF,

(input.charCodeAt(i) >>> 8) & 0xFF);

return output;

}

我缺少什么?

谢谢你

2012-03-13

PhilC

+0

你确定你选择了正确的UTF-16吗? –

2012-03-13 15:52:57

+0

考虑到你正在循环11次(original_to_length == 33,to_length == 22),我非常惊讶地看到22行打印。 –

2012-03-13 16:04:50

+0

抱歉,我的忘记.... to_length变成11,所以差异是22 –

2012-03-13 17:04:47

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值