blake2b算法使用

编程

public static String blake2b(String data) {

try {

byte[] dataBytes = data.getBytes("utf-8");

return blake2b(dataBytes);

} catch (Exception e) {

e.printStackTrace();

}

return null;

}

public static String blake2b(byte[] data) {

Blake2b blake2b = new Blake2b(256);

blake2b.update(data, 0, data.length);

byte[] digest = new byte[32];

int size = blake2b.digest(digest, 0);

if (size > 0) {

return Hex.encodeHexString(digest);

}

return null;

}

public static String blake2b(InputStream data) {

try {

Blake2b blake2b = new Blake2b(256);

byte[] digest = new byte[32];

final byte[] buffer = new byte[1024];

int read = data.read(buffer, 0, 1024);

while (read > -1) {

blake2b.update(buffer, 0, read);

read = data.read(buffer, 0, 1024);

}

blake2b.digest(digest, 0);

return Hex.encodeHexString(digest);

} catch (Exception e) {

e.printStackTrace();

}

return null;

}

public static String blake2bFile(String file) {

if (StringUtils.isNotBlank(file)) {

try {

return blake2b(new FileInputStream(file));

} catch (IOException e) {

e.printStackTrace();

}

}

return null;

}

 

以上是 blake2b算法使用 的全部内容, 来源链接: utcz.com/z/511996.html

回到顶部