我想在一个ActionListener
类中使用以下代码。
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(key.getBytes("UTF-8"));
BigInteger HashValue = new BigInteger(javax.xml.bind.DatatypeConverter.printHexBinary(hash).toLowerCase(), 16);
String HashValueString = HashValue.toString();
但是"SHA-256"
and"UTF-8"
不能以任何方式导入。当我在控制台程序中执行此操作时,我可以通过以下方式解决此问题:
public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException
但是我不能ActionListener
上课。我该如何解决这个问题?