有能将以下这段java代码翻译成GO语言的大神么 求助

Tanfuren 2016-10-07 05:24:29
求助大咖们:

public static String sign1(byte[] data, long timestamp, PrivateKey key) throws Exception {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(data);
if (timestamp > 0) {
byte[] buffer = new byte[8];
buffer[0] = (byte) (timestamp >>> 56);
buffer[1] = (byte) (timestamp >>> 48);
buffer[2] = (byte) (timestamp >>> 40);
buffer[3] = (byte) (timestamp >>> 32);
buffer[4] = (byte) (timestamp >>> 24);
buffer[5] = (byte) (timestamp >>> 16);
buffer[6] = (byte) (timestamp >>> 8);
buffer[7] = (byte) (timestamp >>> 0);

md.update(buffer);
}

byte[] hash = md.digest();
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encrypted = cipher.doFinal(hash);
return HexBin.encode(encrypted);

}

以上实现逻辑是:1.先将字符串做hash; 2. 用户私钥对hash做加密(注意是私钥)3. 加密的结果用hex进行编码
其中私钥是用户在pfx证书中读取的私钥;
...全文
1601 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangxingge2010 2016-11-18
  • 打赏
  • 举报
回复
对了,RSA你加密给个公钥就好了,你给私钥出去等于钥匙送出去了。
wangxingge2010 2016-11-18
  • 打赏
  • 举报
回复
40分,要做这个吗?? 太少了啊。。。 这东西写的话也要20分钟吧。。

2,190

社区成员

发帖
与我相关
我的任务
社区描述
go语言学习与交流版
社区管理员
  • go语言社区
  • Freeman Z
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧