List of usage examples for org.apache.commons.codec.binary Hex encodeHex
public static char[] encodeHex(byte[] data)
From source file:com.trailmagic.user.UserLoginModule.java
public static String encodePassword(char[] password) throws RuntimeException { try {//from w w w .j a va 2 s . c o m MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM); byte[] passBytes = new byte[password.length]; for (int i = 0; i < passBytes.length; i++) { passBytes[i] = (byte) password[i]; } return new String(Hex.encodeHex(md.digest(passBytes))); } catch (NoSuchAlgorithmException e) { s_log.error("Digest algorithm not found: " + HASH_ALGORITHM); throw new RuntimeException(e); } }
From source file:com.example.ExerciseMe.tvmclient.AmazonTVMClient.java
/** * Creates a 128-bit random string./*from w ww .j ava 2 s .c o m*/ */ public String generateRandomString() { SecureRandom random = new SecureRandom(); byte[] randomBytes = random.generateSeed(16); return new String(Hex.encodeHex(randomBytes)); }
From source file:io.moquette.spi.impl.security.FileAuthenticator.java
@Override public boolean checkValid(String clientId, String username, byte[] password) { if (username == null || password == null) { LOG.info("username or password was null"); return false; }//from w w w. j a v a 2 s.c o m String foundPwq = m_identities.get(username); if (foundPwq == null) { return false; } m_digest.update(password); byte[] digest = m_digest.digest(); String encodedPasswd = new String(Hex.encodeHex(digest)); return foundPwq.equals(encodedPasswd); }
From source file:be.fedict.hsm.model.SignatureServiceBean.java
@Override public byte[] sign(String digestMethodAlgorithm, byte[] digestValue, String keyAlias) throws NoSuchAlgorithmException { LOG.debug("digest method algorithm: " + digestMethodAlgorithm); LOG.debug("key alias: " + keyAlias); Principal callerPrincipal = this.sessionContext.getCallerPrincipal(); LOG.debug("caller principal: " + callerPrincipal.getName()); LOG.debug(/* w w w . j av a 2 s . c o m*/ "caller in role application: " + this.sessionContext.isCallerInRole(ApplicationRoles.APPLICATION)); long appId = Long.parseLong(callerPrincipal.getName()); ApplicationKeyEntity applicationKeyEntity = this.entityManager.find(ApplicationKeyEntity.class, new ApplicationKeyId(appId, keyAlias)); if (null == applicationKeyEntity) { throw new NoSuchAlgorithmException("unknown key alias: " + keyAlias); } String keyStoreAlias = applicationKeyEntity.getKeyStoreKeyAlias(); long keyStoreId = applicationKeyEntity.getKeyStore().getId(); String digestAlgo = digestMethodToDigestAlgo.get(digestMethodAlgorithm); if (null == digestAlgo) { throw new IllegalArgumentException("unsupported digest method algo: " + digestMethodAlgorithm); } byte[] signatureValue; try { signatureValue = this.keyStoreSingletonBean.sign(keyStoreId, keyStoreAlias, digestAlgo, digestValue); } catch (Exception e) { LOG.error("signature error: " + e.getMessage()); return null; } AuditEntity auditEntity = new AuditEntity(applicationKeyEntity.getApplication().getName(), keyAlias, applicationKeyEntity.getKeyStore().getName(), keyStoreAlias, new String(Hex.encodeHex(digestValue))); this.entityManager.persist(auditEntity); return signatureValue; }
From source file:mvm.rya.mongodb.dao.SimpleMongoDBNamespaceManager.java
@Override public void addNamespace(String prefix, String namespace) throws RyaDAOException { String id = prefix;//from w w w .j a v a 2 s .c om byte[] bytes = id.getBytes(); try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); bytes = digest.digest(bytes); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } BasicDBObject doc = new BasicDBObject(ID, new String(Hex.encodeHex(bytes))).append(PREFIX, prefix) .append(NAMESPACE, namespace); nsColl.insert(doc); }
From source file:com.ad.mediasharing.tvmclient.AmazonTVMClient.java
/** * Creates a 128-bit random string.//from w w w.jav a 2 s .c o m */ public String generateRandomString() { SecureRandom random = new SecureRandom(); byte[] randomBytes = random.generateSeed(16); String randomString = new String(Hex.encodeHex(randomBytes)); return randomString; }
From source file:net.padlocksoftware.padlock.validator.ValidatorTest.java
License:asdf
@Test public void testBlacklist() throws Exception { KeyPair pair = KeyManager.createKeyPair(); License license = LicenseFactory.createLicense(); license.addProperty("Name", "Jason Nichols"); license.addProperty("Email", "jason@padlocksoftware.net"); license.addProperty("Gibberish", "qwertyasdfg"); LicenseSigner signer = LicenseSigner.createLicenseSigner((DSAPrivateKey) pair.getPrivate()); signer.sign(license);//from w w w .j a v a 2 s . com String key = new String(Hex.encodeHex(pair.getPublic().getEncoded())); Validator validator = new Validator(license, key); validator.addBlacklistedLicense(license.getLicenseSignatureString()); boolean ex = false; try { validator.validate(); } catch (ValidatorException e) { ex = true; } assertTrue(ex); }
From source file:hudson.plugins.ec2.EC2AxisPrivateKey.java
static String digest(PrivateKey k) throws IOException { try {/* w w w. j av a 2 s .c om*/ MessageDigest md5 = MessageDigest.getInstance("SHA1"); DigestInputStream in = new DigestInputStream(new ByteArrayInputStream(k.getEncoded()), md5); try { while (in.read(new byte[128]) > 0) ; // simply discard the input } finally { in.close(); } StringBuilder buf = new StringBuilder(); char[] hex = Hex.encodeHex(md5.digest()); for (int i = 0; i < hex.length; i += 2) { if (buf.length() > 0) buf.append(':'); buf.append(hex, i, 2); } return buf.toString(); } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); } }
From source file:com.openvcx.conference.KeyGenerator.java
/** * Hex encodes a sequence of bytes//from ww w . j av a 2s. com * @param raw The input byte sequence * @return The hex encoded bytes */ public static String toHex(byte[] raw) { return new String(Hex.encodeHex(raw)); }
From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.sav.SAVFileReaderSpi.java
@Override public boolean canDecodeInput(BufferedInputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("stream == null!"); }// w w w . j ava 2s .c o m dbgLog.fine("\napplying the sav test: inputstream case\n"); byte[] b = new byte[SAV_HEADER_SIZE]; if (stream.markSupported()) { stream.mark(0); } int nbytes = stream.read(b, 0, SAV_HEADER_SIZE); if (nbytes == 0) { throw new IOException(); } //printHexDump(b, "hex dump of the byte-array"); dbgLog.fine( "hex dump of the 1st 4 bytes[$FL2 == 24 46 4C 32]=" + (new String(Hex.encodeHex(b))).toUpperCase()); if (stream.markSupported()) { stream.reset(); } boolean DEBUG = false; String hdr4sav = new String(b); dbgLog.fine("from string[$FL2 == 24 46 4C 32]=" + new String(Hex.encodeHex(b)).toUpperCase()); if (hdr4sav.equals(SAV_FILE_SIGNATURE)) { dbgLog.fine("this file is spss-sav type"); return true; } else { dbgLog.fine("this file is NOT spss-sav type"); return false; } }