惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
腾讯CDC
GbyAI
GbyAI
I
InfoQ
博客园 - Franky
G
Google Developers Blog
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
Vercel News
Vercel News
博客园_首页
MyScale Blog
MyScale Blog
Martin Fowler
Martin Fowler
N
Netflix TechBlog - Medium
V
V2EX
T
The Blog of Author Tim Ferriss
M
MIT News - Artificial intelligence
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
大猫的无限游戏
大猫的无限游戏
The GitHub Blog
The GitHub Blog

博客园 - 筱老邪

2026年读书清单,及java技术的巩固 请求处理 图片转为为流的处理 编码和解码 C#与Java互通AES算法加密解密 在Java和C#中计算SHA-1哈希 .net5读取xml文件 部署linux 踩坑 多线程 .net知识点 下载文件,204问题 debug和release的web.config分开配置 数据库的索引查找 sql 查询出符合条件的表增加字段 HTTP状态码:400\500 错误代码 - 筱老邪 - 博客园 linq 两个list交集差集处理 rabbitMQ的使用 rabbitMQ的部署安装 sql 游标循环
SHA1签名算法,JAVA和C#
筱老邪 · 2023-07-28 · via 博客园 - 筱老邪

java:

 1 public static void main(String[] args) throws NoSuchAlgorithmException {
 2     String token = "31a4a1aa-cffc-4aca-9ef6-0497edf7fbed";
 3     String nonce = "Rzem0rlz19e6GZuZuFKyDzaxiS4baaqn8uvxVnntXKS";
 4     String  timestamp = "1646790230854428120";
 5     String dataEncrypt= "abcdefg";
 6     final String[] arrayStrs = { token, timestamp, nonce, dataEncrypt};
 7     Arrays.sort(arrayStrs);
 8     String sTemp = "";
 9     for (final String s : arrayStrs) {
10         sTemp += s;
11     }
12     final MessageDigest md = MessageDigest.getInstance("SHA-1");
13     md.update(sTemp.getBytes());
14     final byte[] digest = md.digest();
15     String signature = "";
16     for (final byte b : digest) {
17         signature += String.format("%02x", b);
18     }
19     System.out.println(signature);
20     return;
21 
22 }

C#:
 1 static void Main(string[] args)
 2 {
 3 string token = "31a4a1aa-cffc-4aca-9ef6-0497edf7fbed";
 4 string nonce = "Rzem0rlz19e6GZuZuFKyDzaxiS4baaqn8uvxVnntXKS";
 5 string timestamp = "1646790230854428120";
 6 string dataEncrypt = "abcdefg";
 7 string[] arrayStrs = { token, timestamp, nonce, dataEncrypt};
 8 
 9 Array.Sort(arrayStrs, string.CompareOrdinal);
10 string sTemp = String.Join("", arrayStrs);
11 
12 string AA = testHash(sTemp);
13 Console.WriteLine($"SHA1 :{AA}");
14 Console.ReadKey();
15 return;
16 }
17 
18 public static string testHash(string sTemp) {
19 byte[] key = System.Text.Encoding.Default.GetBytes(sTemp);
20 SHA1 sha1 = SHA1Managed.Create();
21 byte[] hash = sha1.ComputeHash(key);
22 string result="";
23 foreach (byte b in hash)
24 {
25 result += String.Format("{0:x2}", b);
26 }
27 return result;
28 }