示例#1
0
 /** @throws UnsupportedOperationException if not supported */
 public MessageDigest getDigestInstance() {
   if (digestName.equals("SHA-1")) return SHA1.getInstance();
   if (digestName.equals("SHA-256")) return SHA256Generator.getDigestInstance();
   try {
     return MessageDigest.getInstance(digestName);
   } catch (NoSuchAlgorithmException e) {
     throw new UnsupportedOperationException(e);
   }
 }
示例#2
0
文件: DSAEngine.java 项目: hfeeki/I2P
 /**
  * Reads the stream until EOF. Does not close the stream.
  *
  * @return hash SHA-1 hash, NOT a SHA-256 hash
  */
 public SHA1Hash calculateHash(InputStream in) {
   MessageDigest digest = SHA1.getInstance();
   byte buf[] = new byte[64];
   int read = 0;
   try {
     while ((read = in.read(buf)) != -1) {
       digest.update(buf, 0, read);
     }
   } catch (IOException ioe) {
     if (_log.shouldLog(Log.WARN)) _log.warn("Unable to hash the stream", ioe);
     return null;
   }
   return new SHA1Hash(digest.digest());
 }
示例#3
0
 @Provides
 @Singleton
 SHA1 provideSHA1() {
   return SHA1.getInstance();
 }
示例#4
0
文件: DSAEngine.java 项目: hfeeki/I2P
 /** @return hash SHA-1 hash, NOT a SHA-256 hash */
 public static SHA1Hash calculateHash(byte[] source, int offset, int len) {
   MessageDigest h = SHA1.getInstance();
   h.update(source, offset, len);
   byte digested[] = h.digest();
   return new SHA1Hash(digested);
 }