use of java.security.MessageDigest in project cas by apereo.
the class DigestUtils method rawDigest.
/**
* Computes digest.
*
* @param alg Digest algorithm to use
* @param data data to be hashed
* @return hash
*/
public static byte[] rawDigest(final String alg, final byte[] data) {
try {
final MessageDigest digest = MessageDigest.getInstance(alg);
digest.reset();
return digest.digest(data);
} catch (final Exception cause) {
throw new SecurityException(cause);
}
}
use of java.security.MessageDigest in project crate by crate.
the class Blobs method digest.
public static byte[] digest(String content) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-1");
digest.reset();
digest.update(content.getBytes(StandardCharsets.UTF_8));
return digest.digest();
} catch (NoSuchAlgorithmException e) {
return null;
}
}
use of java.security.MessageDigest in project sockjs-netty by cgbystrom.
the class IframePage method generateMd5.
private static String generateMd5(String value) {
String encryptedString = null;
byte[] bytesToBeEncrypted;
try {
// convert string to bytes using a encoding scheme
bytesToBeEncrypted = value.getBytes("UTF-8");
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] theDigest = md.digest(bytesToBeEncrypted);
// convert each byte to a hexadecimal digit
Formatter formatter = new Formatter();
for (byte b : theDigest) {
formatter.format("%02x", b);
}
encryptedString = formatter.toString().toLowerCase();
} catch (UnsupportedEncodingException e) {
// FIXME: Return proper HTTP error
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
// FIXME: Return proper HTTP error
e.printStackTrace();
}
return encryptedString;
}
use of java.security.MessageDigest in project UltimateAndroid by cymcsg.
the class TripleDES method decrypt.
/**
* Decrypt the message with TripleDES
*
* @param message
* @return
* @throws Exception
*/
public static String decrypt(String message) throws Exception {
if (message == null || message == "")
return "";
byte[] values = Base64decoding(message, 0);
final MessageDigest md = MessageDigest.getInstance("SHA-1");
final byte[] digestOfPassword = md.digest(token.getBytes("utf-8"));
final byte[] keyBytes = copyOf(digestOfPassword, 24);
for (int j = 0, k = 16; j < 8; ) {
keyBytes[k++] = keyBytes[j++];
}
final SecretKey key = new SecretKeySpec(keyBytes, "DESede");
String s1 = "12345678";
byte[] bytes = s1.getBytes();
final IvParameterSpec iv = new IvParameterSpec(bytes);
final Cipher decipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
decipher.init(Cipher.DECRYPT_MODE, key, iv);
final byte[] plainText = decipher.doFinal(values);
return new String(plainText, "UTF-8");
}
use of java.security.MessageDigest in project UltimateAndroid by cymcsg.
the class TripleDES method decrypt.
/**
* Decrypt the message with TripleDES
*
* @param message
* @return
* @throws Exception
*/
public static String decrypt(byte[] message) throws Exception {
byte[] values = Base64decodingByte(message, 0);
final MessageDigest md = MessageDigest.getInstance("SHA-1");
final byte[] digestOfPassword = md.digest(token.getBytes("utf-8"));
final byte[] keyBytes = copyOf(digestOfPassword, 24);
for (int j = 0, k = 16; j < 8; ) {
keyBytes[k++] = keyBytes[j++];
}
final SecretKey key = new SecretKeySpec(keyBytes, "DESede");
String s1 = "12345678";
byte[] bytes = s1.getBytes();
final IvParameterSpec iv = new IvParameterSpec(bytes);
final Cipher decipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
decipher.init(Cipher.DECRYPT_MODE, key, iv);
final byte[] plainText = decipher.doFinal(values);
return new String(plainText, "UTF-8");
}
Aggregations