Mercurial Hosting > luan
diff src/luan/modules/BinaryLuan.java @ 1649:f7e2df85fc0a
add String.digest_message
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 29 Mar 2022 16:07:01 -0600 |
parents | e0cf0d108a77 |
children |
line wrap: on
line diff
--- a/src/luan/modules/BinaryLuan.java Mon Mar 28 18:00:12 2022 +0200 +++ b/src/luan/modules/BinaryLuan.java Tue Mar 29 16:07:01 2022 -0600 @@ -1,6 +1,8 @@ package luan.modules; import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import luan.Luan; import luan.LuanTable; import luan.LuanFunction; @@ -55,4 +57,16 @@ return charsetName!=null ? new String(binary,charsetName) : toString(binary); } + public static byte[] digest_message(String algorithm,byte[] input) throws NoSuchAlgorithmException { + return MessageDigest.getInstance(algorithm).digest(input); + } + + public static String to_hex(byte[] a) { + StringBuilder sb = new StringBuilder(); + for( byte b : a ) { + sb.append( String.format("%02x",b) ); + } + return sb.toString(); + } + }