use of java.security.NoSuchAlgorithmException in project hbase by apache.
the class Encryption method pbkdf128.
/**
* Return a 128 bit key derived from the concatenation of the supplied
* arguments using PBKDF2WithHmacSHA1 at 10,000 iterations.
*
*/
public static byte[] pbkdf128(String... args) {
byte[] salt = new byte[128];
Bytes.random(salt);
StringBuilder sb = new StringBuilder();
for (String s : args) {
sb.append(s);
}
PBEKeySpec spec = new PBEKeySpec(sb.toString().toCharArray(), salt, 10000, 128);
try {
return SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(spec).getEncoded();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (InvalidKeySpecException e) {
throw new RuntimeException(e);
}
}
use of java.security.NoSuchAlgorithmException in project hbase by apache.
the class Encryption method hash128.
/**
* Return the MD5 digest of the concatenation of the supplied arguments.
*/
public static byte[] hash128(String... args) {
byte[] result = new byte[16];
try {
MessageDigest md = MessageDigest.getInstance("MD5");
for (String arg : args) {
md.update(Bytes.toBytes(arg));
}
md.digest(result, 0, result.length);
return result;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (DigestException e) {
throw new RuntimeException(e);
}
}
use of java.security.NoSuchAlgorithmException in project hbase by apache.
the class KeyStoreKeyProvider method load.
protected void load(URI uri) throws IOException {
String path = uri.getPath();
if (path == null || path.isEmpty()) {
throw new RuntimeException("KeyProvider parameters should specify a path");
}
InputStream is = new FileInputStream(new File(path));
try {
store.load(is, password);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (CertificateException e) {
throw new RuntimeException(e);
} finally {
is.close();
}
}
use of java.security.NoSuchAlgorithmException in project qpid by apache.
the class SchemaClass method generateHash.
/**
* Return a hash generated over the body of the schema, and return a representation of the hash
* @return a hash generated over the body of the schema, and return a representation of the hash
*/
public final UUID generateHash() {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
updateHash(md5);
return UUID.nameUUIDFromBytes(md5.digest());
} catch (NoSuchAlgorithmException nsae) {
}
return null;
}
use of java.security.NoSuchAlgorithmException in project hive by apache.
the class GenericUDFSha2 method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
checkArgsSize(arguments, 2, 2);
checkArgPrimitive(arguments, 0);
checkArgPrimitive(arguments, 1);
// the function should support both string and binary input types
checkArgGroups(arguments, 0, inputTypes, STRING_GROUP, BINARY_GROUP);
checkArgGroups(arguments, 1, inputTypes, NUMERIC_GROUP);
if (PrimitiveObjectInspectorUtils.getPrimitiveGrouping(inputTypes[0]) == STRING_GROUP) {
obtainStringConverter(arguments, 0, inputTypes, converters);
isStr = true;
} else {
GenericUDFParamUtils.obtainBinaryConverter(arguments, 0, inputTypes, converters);
isStr = false;
}
if (arguments[1] instanceof ConstantObjectInspector) {
Integer lenObj = getConstantIntValue(arguments, 1);
if (lenObj != null) {
int len = lenObj.intValue();
if (len == 0) {
len = 256;
}
try {
digest = MessageDigest.getInstance("SHA-" + len);
} catch (NoSuchAlgorithmException e) {
// ignore
}
}
} else {
throw new UDFArgumentTypeException(1, getFuncName() + " only takes constant as " + getArgOrder(1) + " argument");
}
ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
return outputOI;
}
Aggregations