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

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Java實現SHA1加密代碼實例

Java實現SHA1加密代碼實例

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

這篇文章給大家分享了Java實現SHA1加密的相關實例代碼,有興趣的朋友可以測試參考下。

微信接入中需要用到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
/*
 * 微信公眾平臺(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);
    // 把密文轉換成十六進制的字符串形式
    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);
    }
  }
}

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 爱福利视频一区二区 | 久久亚洲国产成人影院 | 男人机机桶女人机机 | 91国内精品线免费播放 | 日韩无砖专区2020在线 | 精品欧美一区二区三区在线观看 | 国产99re在线观看69热 | 娇妻中日久久持久久 | 日本红色高清免费观看 | 亚洲精品欧洲久久婷婷99 | 16男男gaygays| 日本激情在线 | 久久久精品免费免费直播 | 久久热这里面只有精品 | 色导行| 99草精品视频 | 狠狠干狠狠插 | 506rr亚洲欧美| 久久综合给会久久狠狠狠 | 亚洲人成网站在线观看妞妞网 | 欧美日韩一级视频 | 国产精品永久免费10000 | 精品免费tv久久久久久久 | 亚洲va韩国va欧美va天堂 | 无颜之月全集免费观看 | 免费岛国 | 亚洲区在线播放 | 91日本在线观看亚洲精品 | 亚洲午夜久久久久久91 | 99精品在线视频 | 奇米影视777最新在线 | 日韩伦理在线看 | 国产精品视频第一页 | 热久久最新地址 | 天天操天天干天天做 | 91在线亚洲综合在线 | 久久精品国产在热亚洲完整版 | 99久久国产亚洲综合精品 | 暖暖 免费 高清 日本 在线1 | 国产午夜精品福利 | 国产精品va在线观看不 |