传递JSON输入字符串,需要使用带有Base64编码器格式的SHA1转换为hashvalue ..
如下所示,我试过了,
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.codec.binary.Base64;
import org.json.JSONObject;
import java.util.Base64.Encoder;;
public class HashTextTest {
public static void main(String[] args) throws NoSuchAlgorithmException {
System.out.println(sha1(""));
}
static String sha1(String input) throws NoSuchAlgorithmException {
MessageDigest mDigest = MessageDigest.getInstance("SHA1");
byte[] result = mDigest.digest(input.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
}
}
但是上面的代码只接受字符串输入,这里不能传递JSON字符串,并且它完全返回Hashvalue但我需要Base64Encoder格式的hashvalue ..
帮帮我