Search in sources :

Example 11 with NoSuchAlgorithmException

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);
    }
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException)

Example 12 with NoSuchAlgorithmException

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);
    }
}
Also used : DigestException(java.security.DigestException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 13 with NoSuchAlgorithmException

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();
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 14 with NoSuchAlgorithmException

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;
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 15 with NoSuchAlgorithmException

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;
}
Also used : ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1403 MessageDigest (java.security.MessageDigest)548 IOException (java.io.IOException)328 InvalidKeyException (java.security.InvalidKeyException)242 KeyStoreException (java.security.KeyStoreException)168 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)145 CertificateException (java.security.cert.CertificateException)138 UnsupportedEncodingException (java.io.UnsupportedEncodingException)131 KeyManagementException (java.security.KeyManagementException)105 KeyFactory (java.security.KeyFactory)96 NoSuchProviderException (java.security.NoSuchProviderException)93 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)89 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)79 UnrecoverableKeyException (java.security.UnrecoverableKeyException)78 KeyStore (java.security.KeyStore)73 SecureRandom (java.security.SecureRandom)72 SSLContext (javax.net.ssl.SSLContext)72 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)69 BadPaddingException (javax.crypto.BadPaddingException)69 Cipher (javax.crypto.Cipher)69