一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - Java實(shí)現(xiàn)SHA1加密代碼實(shí)例

Java實(shí)現(xiàn)SHA1加密代碼實(shí)例

2021-05-17 15:06花2不謝 Java教程

這篇文章給大家分享了Java實(shí)現(xiàn)SHA1加密的相關(guān)實(shí)例代碼,有興趣的朋友可以測(cè)試參考下。

微信接入中需要用到sha1的算法。java版的sha1加密如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * 微信公眾平臺(tái)(java) sdk
 *
 * copyright (c) 2016, ansitech network technology co.,ltd all rights reserved.
 * http://www.ansitech.com/weixin/sdk/
 *
 * licensed under the apache license, version 2.0 (the "license");
 * you may not use this file except in compliance with the license.
 * you may obtain a copy of the license at
 *
 *   http://www.apache.org/licenses/license-2.0
 *
 * unless required by applicable law or agreed to in writing, software
 * distributed under the license is distributed on an "as is" basis,
 * without warranties or conditions of any kind, either express or implied.
 * see the license for the specific language governing permissions and
 * limitations under the license.
 */
package com.levi.utils;
 
import java.security.messagedigest;
 
/**
 * <p>title: sha1算法</p>
 *
 * @author levi
 */
public final class sha1 {
 
  private static final char[] hex_digits = {'0', '1', '2', '3', '4', '5',
              '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
 
  /**
   * takes the raw bytes from the digest and formats them correct.
   *
   * @param bytes the raw bytes from the digest.
   * @return the formatted bytes.
   */
  private static string getformattedtext(byte[] bytes) {
    int len = bytes.length;
    stringbuilder buf = new stringbuilder(len * 2);
    // 把密文轉(zhuǎn)換成十六進(jìn)制的字符串形式
    for (int j = 0; j < len; j++) {
      buf.append(hex_digits[(bytes[j] >> 4) & 0x0f]);
      buf.append(hex_digits[bytes[j] & 0x0f]);
    }
    return buf.tostring();
  }
 
  public static string encode(string str) {
    if (str == null) {
      return null;
    }
    try {
      messagedigest messagedigest = messagedigest.getinstance("sha1");
      messagedigest.update(str.getbytes());
      return getformattedtext(messagedigest.digest());
    } catch (exception e) {
      throw new runtimeexception(e);
    }
  }
}

如果需要做微信接入,直接把上面的復(fù)制新建一個(gè)類即可使用,我自己做好的,測(cè)試微信接入成功。

原文鏈接:https://blog.csdn.net/qq_25821067/article/details/53643365

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 久久综合给会久久狠狠狠 | 99精品免费在线 | 日本性生活免费看 | a级黄色视屏 | 久久婷婷丁香五月色综合啪免费 | 国产精品自在欧美一区 | 国产二区三区 | 亚洲xxxxxhd奶水女人 | 91麻豆精品| xvideoscom极品肌肉警察 | japan在线观看 | 2015台湾永久免费平台 | a级精品九九九大片免费看 a级动漫 | 亚洲 欧美 国产 综合久久 | 日日操免费视频 | 福利视频一区二区思瑞 | 亚洲天堂伦理 | 亚洲国产精品久久久久 | 欧美日韩在线观看一区二区 | 久久综合香蕉久久久久久久 | 国产视频三区 | 日本高清视频一区二区 | 天天操夜夜操狠狠操 | 色播开心网 | 奇米网狠狠网 | 办公室大战秘书呻吟 | 娇女的呻吟亲女禁忌h16 | 99热视频| 亚洲欧美在线观看一区二区 | 天堂网在线.www天堂在线资源 | 韩国三级日本三级香港三级黄 | 美女艹b| 韩日理论片 | 婷婷色天使在线视频观看 | 亚洲第一男人网站 | 国产精品亚洲专区一区 | 精品蜜臀AV在线天堂 | 国产精品反差婊在线观看 | a国产在线 | 女性全身裸露无遮挡 | 亚洲国产99 |