comparison 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
comparison
equal deleted inserted replaced
1648:224af797b1f9 1649:f7e2df85fc0a
1 package luan.modules; 1 package luan.modules;
2 2
3 import java.io.UnsupportedEncodingException; 3 import java.io.UnsupportedEncodingException;
4 import java.security.MessageDigest;
5 import java.security.NoSuchAlgorithmException;
4 import luan.Luan; 6 import luan.Luan;
5 import luan.LuanTable; 7 import luan.LuanTable;
6 import luan.LuanFunction; 8 import luan.LuanFunction;
7 import luan.LuanException; 9 import luan.LuanException;
8 10
53 public static String to_string(byte[] binary,String charsetName) throws LuanException, UnsupportedEncodingException { 55 public static String to_string(byte[] binary,String charsetName) throws LuanException, UnsupportedEncodingException {
54 Utils.checkNotNull(binary); 56 Utils.checkNotNull(binary);
55 return charsetName!=null ? new String(binary,charsetName) : toString(binary); 57 return charsetName!=null ? new String(binary,charsetName) : toString(binary);
56 } 58 }
57 59
60 public static byte[] digest_message(String algorithm,byte[] input) throws NoSuchAlgorithmException {
61 return MessageDigest.getInstance(algorithm).digest(input);
62 }
63
64 public static String to_hex(byte[] a) {
65 StringBuilder sb = new StringBuilder();
66 for( byte b : a ) {
67 sb.append( String.format("%02x",b) );
68 }
69 return sb.toString();
70 }
71
58 } 72 }