/** * {@inheritDoc} * * @see org.modeshape.common.text.TextEncoder#encode(java.lang.String) */ @Override public String encode( String text ) { try { byte[] hash = SecureHash.getHash(algorithm, text.getBytes()); String result = Base64.encodeBytes(hash); return result.length() < maxLength ? result : result.substring(0, maxLength); } catch (NoSuchAlgorithmException e) { return text; } }
/** * {@inheritDoc} * * @see org.modeshape.common.text.TextEncoder#encode(java.lang.String) */ @Override public String encode( String text ) { try { byte[] hash = SecureHash.getHash(algorithm, text.getBytes()); String result = Base64.encodeBytes(hash); return result.length() < maxLength ? result : result.substring(0, maxLength); } catch (NoSuchAlgorithmException e) { return text; } }
private synchronized BinaryKey generateHash() { if (this.hash == null) { try { byte[] hashBytes = SecureHash.getHash(SecureHash.Algorithm.SHA_1, convertURLtoFile(this.content)); this.hash = new BinaryKey(hashBytes); } catch (Exception e) { throw new RuntimeException(e); } } return this.hash; }
public InMemoryTestBinary( byte[] bytes ) { try { this.bytes = bytes; this.hash = SecureHash.getHash(SecureHash.Algorithm.SHA_1, bytes); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
private synchronized BinaryKey generateHash() { if (this.hash == null) { try { byte[] hashBytes = SecureHash.getHash(SecureHash.Algorithm.SHA_1, convertURLtoFile(this.content)); this.hash = new BinaryKey(hashBytes); } catch (Exception e) { throw new RuntimeException(e); } } return this.hash; }
/** * Computes the sha1 value for the given string. * * @param string a non-null string * @return the SHA1 value for the given string. */ public static String sha1( String string ) { try { byte[] sha1 = SecureHash.getHash(SecureHash.Algorithm.SHA_1, string.getBytes()); return SecureHash.asHexString(sha1); } catch (NoSuchAlgorithmException e) { throw new SystemFailureException(e); } }
public static BinaryKey keyFor( byte[] content ) { try { byte[] hash = SecureHash.getHash(ALGORITHM, content); return new BinaryKey(hash); } catch (NoSuchAlgorithmException e) { throw new SystemFailureException(e); } }
public static BinaryKey keyFor( byte[] sha1 ) { try { byte[] hash = SecureHash.getHash(Algorithm.SHA_1, sha1); return new BinaryKey(hash); } catch (NoSuchAlgorithmException e) { throw new SystemFailureException(e); } }
/** * Get the hash of the supplied content, using the supplied digest algorithm. * * @param algorithm the hashing function algorithm that should be used * @param content the content to be hashed; may not be null * @return the hash of the contents as a byte array * @throws NoSuchAlgorithmException if the supplied algorithm could not be found * @throws IllegalArgumentException if the algorithm is null */ public static byte[] getHash( Algorithm algorithm, byte[] content ) throws NoSuchAlgorithmException { CheckArg.isNotNull(algorithm, "algorithm"); return getHash(algorithm.digestName(), content); }
public static BinaryKey keyFor( byte[] sha1 ) { try { byte[] hash = SecureHash.getHash(Algorithm.SHA_1, sha1); return new BinaryKey(hash); } catch (NoSuchAlgorithmException e) { throw new SystemFailureException(e); } }
public static BinaryKey keyFor( byte[] content ) { try { byte[] hash = SecureHash.getHash(ALGORITHM, content); return new BinaryKey(hash); } catch (NoSuchAlgorithmException e) { throw new SystemFailureException(e); } }
/** * Get the hash of the supplied content, using the supplied digest algorithm. * * @param algorithm the hashing function algorithm that should be used * @param content the content to be hashed; may not be null * @return the hash of the contents as a byte array * @throws NoSuchAlgorithmException if the supplied algorithm could not be found * @throws IllegalArgumentException if the algorithm is null */ public static byte[] getHash( Algorithm algorithm, byte[] content ) throws NoSuchAlgorithmException { CheckArg.isNotNull(algorithm, "algorithm"); return getHash(algorithm.digestName(), content); }
/** * Get the hash of the supplied content, using the supplied digest algorithm. * * @param algorithm the hashing function algorithm that should be used * @param file the file containing the content to be hashed; may not be null * @return the hash of the contents as a byte array * @throws NoSuchAlgorithmException if the supplied algorithm could not be found * @throws IllegalArgumentException if the algorithm is null * @throws IOException if there is an error reading the file */ public static byte[] getHash( Algorithm algorithm, File file ) throws NoSuchAlgorithmException, IOException { CheckArg.isNotNull(algorithm, "algorithm"); return getHash(algorithm.digestName(), file); }
/** * Get the hash of the supplied content, using the supplied digest algorithm. * * @param algorithm the hashing function algorithm that should be used * @param file the file containing the content to be hashed; may not be null * @return the hash of the contents as a byte array * @throws NoSuchAlgorithmException if the supplied algorithm could not be found * @throws IllegalArgumentException if the algorithm is null * @throws IOException if there is an error reading the file */ public static byte[] getHash( Algorithm algorithm, File file ) throws NoSuchAlgorithmException, IOException { CheckArg.isNotNull(algorithm, "algorithm"); return getHash(algorithm.digestName(), file); }
/** * Get the hash of the supplied content, using the supplied digest algorithm. * * @param algorithm the hashing function algorithm that should be used * @param stream the stream containing the content to be hashed; may not be null * @return the hash of the contents as a byte array * @throws NoSuchAlgorithmException if the supplied algorithm could not be found * @throws IllegalArgumentException if the algorithm is null * @throws IOException if there is an error reading the stream */ public static byte[] getHash( Algorithm algorithm, InputStream stream ) throws NoSuchAlgorithmException, IOException { CheckArg.isNotNull(algorithm, "algorithm"); return getHash(algorithm.digestName(), stream); }
protected byte[] computeHash( byte[] content ) { try { return SecureHash.getHash(ALGORITHM, content); } catch (NoSuchAlgorithmException e) { if (ALGORITHMS_NOT_FOUND_AND_LOGGED.add(ALGORITHM.digestName())) { Logger.getLogger(getClass()).error(e, GraphI18n.messageDigestNotFound, ALGORITHM.digestName()); } return NO_HASH; } }
public LargeValue get( String obj ) throws NoSuchAlgorithmException { byte[] hash = SecureHash.getHash(SecureHash.Algorithm.SHA_1, obj.getBytes()); return get(hash); }
private static String sha1( String content ) { try { byte[] bytes = SecureHash.getHash(Algorithm.SHA_1, new ByteArrayInputStream(content.getBytes())); return SecureHash.asHexString(bytes); } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }
protected byte[] computeHash( File file ) { try { return SecureHash.getHash(ALGORITHM, file); } catch (NoSuchAlgorithmException e) { if (ALGORITHMS_NOT_FOUND_AND_LOGGED.add(ALGORITHM.digestName())) { Logger.getLogger(getClass()).error(e, GraphI18n.messageDigestNotFound, ALGORITHM.digestName()); } return NO_HASH; } catch (IOException e) { if (ALGORITHMS_NOT_FOUND_AND_LOGGED.add(ALGORITHM.digestName())) { Logger.getLogger(getClass()).error(e, GraphI18n.messageDigestNotFound, ALGORITHM.digestName()); } return NO_HASH; } }
protected byte[] computeHash( InputStream stream ) { try { return SecureHash.getHash(ALGORITHM, stream); } catch (NoSuchAlgorithmException e) { if (ALGORITHMS_NOT_FOUND_AND_LOGGED.add(ALGORITHM.digestName())) { Logger.getLogger(getClass()).error(e, GraphI18n.messageDigestNotFound, ALGORITHM.digestName()); } return NO_HASH; } catch (IOException e) { if (ALGORITHMS_NOT_FOUND_AND_LOGGED.add(ALGORITHM.digestName())) { Logger.getLogger(getClass()).error(e, GraphI18n.messageDigestNotFound, ALGORITHM.digestName()); } return NO_HASH; } }