ShaCipher.java
627 Bytes
package com.diligrp.cashier.shared.security;
import java.security.MessageDigest;
/**
* SHA散列算法工具类
*/
public class ShaCipher {
private static final String KEY_SHA = "SHA-256";
public static byte[] encrypt(byte[] data) throws Exception {
MessageDigest sha = MessageDigest.getInstance(KEY_SHA);
sha.update(data);
return sha.digest();
}
public static byte[] encrypt(byte[] data, String algorithm) throws Exception {
MessageDigest sha = MessageDigest.getInstance(algorithm);
sha.update(data);
return sha.digest();
}
}