admin管理员组

文章数量:1663645

2023年12月12日发(作者:)

java中实现SHA1安全哈希算法

博主人很懒,直接就贴代码了~~

import eDigest;

/**

* 安全哈希算法 SHA1

* @author lenovo

*

*/

public class SHA1 {

private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',

'e', 'f' };

private static String getFormattedText(byte[] bytes) {

int len = ;

StringBuilder buf = new StringBuilder(len * 2);

// 把密文转换成十六进制的字符串形式

for (int j = 0; j < len; j++) {

(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);

(HEX_DIGITS[bytes[j] & 0x0f]);

}

return ng();

}

public static String encode(String str) {

if (str == null) {

return null;

}

try {

MessageDigest messageDigest = tance("SHA1");

(es());

return getFormattedText(());

} catch (Exception e) {

throw new RuntimeException(e);

}

}

}

本文标签: 字符串算法实现密文形式