예제 #1
0
  private static String digest(InputStream input, String algorithm) throws IOException {
    try {
      MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
      int bufferLength = 1024;
      byte[] buffer = new byte[bufferLength];
      int read = input.read(buffer, 0, bufferLength);

      while (read > -1) {
        messageDigest.update(buffer, 0, read);
        read = input.read(buffer, 0, bufferLength);
      }

      return EncodeUtils.encodeHex(messageDigest.digest());
    } catch (GeneralSecurityException e) {
      throw ExceptionUtils.unchecked(e);
    }
  }
예제 #2
0
 public static String sha1Base64UrlSafe(String input) {
   byte[] digestResult = digest(input, "SHA-1");
   return EncodeUtils.encodeUrlSafeBase64(digestResult);
 }
예제 #3
0
 public static String sha1Hex(String input) {
   byte[] digestResult = digest(input, "SHA-1");
   return EncodeUtils.encodeHex(digestResult);
 }