List of usage examples for java.security MessageDigest digest
public byte[] digest(byte[] input)
From source file:org.trustedanalytics.servicebroker.yarn.utils.YarnTestUtils.java
public static void createDir(ZookeeperCredentials credentials, String path) throws Exception { LOGGER.info("Attempt to create znode: " + path); CuratorFramework tempClient = getNewTempClient(credentials.getConnectionString()); MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] authDigest = md .digest(String.format("%s:%s", credentials.getUsername(), credentials.getPassword()).getBytes()); String authEncoded = new String(Base64.encode(authDigest)); ImmutableList<ACL> acl = ImmutableList.of(new ACL(ZooDefs.Perms.ALL, new Id("digest", String.format("%s:%s", credentials.getUsername(), authEncoded)))); tempClient.create().creatingParentsIfNeeded() //.withACL(acl) .forPath(path);//from w ww. ja v a2 s. c om tempClient.close(); }
From source file:com.apabi.qrcode.utils.DigestUtils.java
/** * , ?md5sha1.//from w w w .j ava 2 s .co m */ private static byte[] digest(final byte[] data, final String algorithm) { try { MessageDigest messageDigest = MessageDigest.getInstance(algorithm); return messageDigest.digest(data); } catch (GeneralSecurityException e) { throw new IllegalStateException("Security exception", e); } }
From source file:com.baidu.rigel.biplatform.ac.util.Md5Util.java
/** * * MD5?/*from w w w .ja v a 2 s .co m*/ * * @param rawPass * @param salt ? * @return md5 * @throws IllegalArgumentException ? */ public static String encode(String rawPass, Object salt) { if (StringUtils.isBlank(rawPass)) { throw new IllegalArgumentException("encode string can not be empty!"); } String saltedPass = mergePasswordAndSalt(rawPass, salt); try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); byte[] digest = messageDigest.digest(saltedPass.getBytes()); return new String(decodeByteArray(digest)); } catch (NoSuchAlgorithmException e) { return rawPass; } }
From source file:shootersubdownloader.Shootersubdownloader.java
static String md5(byte[] bs) { try {//from w w w. j a v a2 s. c o m MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(bs); BigInteger number = new BigInteger(1, messageDigest); String hashtext = number.toString(16); // Now we need to zero pad it if you actually want the full 32 chars. while (hashtext.length() < 32) { hashtext = "0" + hashtext; } return hashtext; } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
From source file:shootersubdownloader.Shootersubdownloader.java
static String md5(String input) { try {/*from w w w . j a va2s . co m*/ MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(input.getBytes()); BigInteger number = new BigInteger(1, messageDigest); String hashtext = number.toString(16); // Now we need to zero pad it if you actually want the full 32 chars. while (hashtext.length() < 32) { hashtext = "0" + hashtext; } return hashtext; } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
From source file:com.agiletec.plugins.jpuserreg.aps.system.services.userreg.util.ShaEncoder.java
public static String encodePassword(String password, String salt) throws NoSuchAlgorithmException { String saltedPass = mergePasswordAndSalt(password, salt, false); MessageDigest messageDigest = MessageDigest.getInstance("SHA"); byte[] digest = messageDigest.digest(saltedPass.getBytes()); return new String(Hex.encodeHex(digest)); }
From source file:com.fujitsu.dc.core.auth.AuthUtils.java
/** * ?Hash?./* w ww . j a v a 2 s . c o m*/ * @param passwd * @return ??? */ public static String hashPassword(final String passwd) { if (passwd == null) { return null; } // DC0 Ruby Code // Digest::SHA256.hexdigest(pw + "Password hash salt value") String str2hash = passwd + DcCoreConfig.getAuthPasswordSalt(); try { MessageDigest md = MessageDigest.getInstance(MD_ALGORITHM); byte[] digestBytes = md.digest(str2hash.getBytes(CharEncoding.UTF_8)); // ???????????DC0????????????? return DcCoreUtils.byteArray2HexString(digestBytes); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:AddSHA1.java
public static String SHA1(String inStr) { MessageDigest md = null; String outStr = null;/* w w w . j ava 2 s. c om*/ try { md = MessageDigest.getInstance("SHA-1"); //SHA-1?MD5 byte[] digest = md.digest(inStr.getBytes()); //byet[]?String outStr = bytetoString(digest); } catch (NoSuchAlgorithmException nsae) { nsae.printStackTrace(); } return outStr; }
From source file:MessageDigestUtil.java
/** * ??????????????????????????/*from w w w . j av a 2s.com*/ * * @param planeText * @return */ public static String digest(String planeText) { MessageDigest digest = createMessageDigest(); byte[] b = planeText.getBytes(); String hex = toHexString(digest.digest(b)); return hex; }
From source file:org.trustedanalytics.servicebroker.hdfs.integration.config.store.ZkStoreTestUtils.java
public static void createDir(ZookeeperCredentials credentials, String path) throws Exception { CuratorFramework tempClient = getNewTempClient(credentials.getConnectionString()); MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] authDigest = md .digest(String.format("%s:%s", credentials.getUsername(), credentials.getPassword()).getBytes()); String authEncoded = new String(Base64.encode(authDigest)); ImmutableList<ACL> acl = ImmutableList.of(new ACL(ZooDefs.Perms.ALL, new Id("digest", String.format("%s:%s", credentials.getUsername(), authEncoded)))); tempClient.create().creatingParentsIfNeeded().withACL(acl).forPath(path); tempClient.close();// w w w. j av a2 s . c o m }