Example usage for javax.crypto Mac getInstance

List of usage examples for javax.crypto Mac getInstance

Introduction

In this page you can find the example usage for javax.crypto Mac getInstance.

Prototype

public static final Mac getInstance(String algorithm) throws NoSuchAlgorithmException 

Source Link

Document

Returns a Mac object that implements the specified MAC algorithm.

Usage

From source file:grabbers.amazon.SignedRequestsHelper.java

/**
 * You must provide the three values below to initialize the helper.
 *
 * @param endpoint       Destination for the requests.
 * @param awsAccessKeyId Your AWS Access Key ID
 * @param awsSecretKey   Your AWS Secret Key
 *///w ww.j ava 2s .c  o  m
public static SignedRequestsHelper getInstance(String endpoint, String awsAccessKeyId, String awsSecretKey)
        throws IllegalArgumentException, UnsupportedEncodingException, NoSuchAlgorithmException,
        InvalidKeyException {
    if (null == endpoint || endpoint.length() == 0) {
        throw new IllegalArgumentException("endPoint is null or empty");
    }
    if (null == awsAccessKeyId || awsAccessKeyId.length() == 0) {
        throw new IllegalArgumentException("awsAccessKeyId is null or empty");
    }
    if (null == awsSecretKey || awsSecretKey.length() == 0) {
        throw new IllegalArgumentException("awsSecretKey is null or empty");
    }

    SignedRequestsHelper instance = new SignedRequestsHelper();
    instance.endpoint = endpoint.toLowerCase();
    instance.awsAccessKeyId = awsAccessKeyId;
    instance.awsSecretKey = awsSecretKey;

    byte[] secretyKeyBytes = instance.awsSecretKey.getBytes(UTF8_CHARSET);
    instance.secretKeySpec = new SecretKeySpec(secretyKeyBytes, HMAC_SHA256_ALGORITHM);
    instance.mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
    instance.mac.init(instance.secretKeySpec);

    return instance;
}

From source file:com.amazon.movies.project.SignedRequestHelper.java

/**
 * You must provide the three values below to initialize the helper.
 *  /*from   w w w  . j a v a  2 s .  c o m*/
 * @param endpoint          Destination for the requests.
 * @param awsAccessKeyId    Your AWS Access Key ID
 * @param awsSecretKey      Your AWS Secret Key
 */
public static SignedRequestHelper getInstance(String endpoint, String awsAccessKeyId, String awsSecretKey)
        throws IllegalArgumentException, UnsupportedEncodingException, NoSuchAlgorithmException,
        InvalidKeyException {
    if (null == endpoint || endpoint.length() == 0) {
        throw new IllegalArgumentException("endpoint is null or empty");
    }
    if (null == awsAccessKeyId || awsAccessKeyId.length() == 0) {
        throw new IllegalArgumentException("awsAccessKeyId is null or empty");
    }
    if (null == awsSecretKey || awsSecretKey.length() == 0) {
        throw new IllegalArgumentException("awsSecretKey is null or empty");
    }

    SignedRequestHelper instance = new SignedRequestHelper();
    instance.endpoint = endpoint.toLowerCase();
    instance.awsAccessKeyId = awsAccessKeyId;
    instance.awsSecretKey = awsSecretKey;

    byte[] secretyKeyBytes = instance.awsSecretKey.getBytes(UTF8_CHARSET);
    instance.secretKeySpec = new SecretKeySpec(secretyKeyBytes, HMAC_SHA256_ALGORITHM);
    instance.mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
    instance.mac.init(instance.secretKeySpec);

    return instance;
}

From source file:org.aws.query.data.SignedRequestsJavaHelper.java

/**
 * You must provide the three values below to initialize the helper.
 *  /*from   ww w.j  a v a2s  .  com*/
 * @param endpoint          Destination for the requests.
 * @param awsAccessKeyId    Your AWS Access Key ID
 * @param awsSecretKey      Your AWS Secret Key
 */
public static SignedRequestsJavaHelper getInstance(String endpoint, String awsAccessKeyId, String awsSecretKey)
        throws IllegalArgumentException, UnsupportedEncodingException, NoSuchAlgorithmException,
        InvalidKeyException {
    if (null == endpoint || endpoint.length() == 0) {
        throw new IllegalArgumentException("endpoint is null or empty");
    }
    if (null == awsAccessKeyId || awsAccessKeyId.length() == 0) {
        throw new IllegalArgumentException("awsAccessKeyId is null or empty");
    }
    if (null == awsSecretKey || awsSecretKey.length() == 0) {
        throw new IllegalArgumentException("awsSecretKey is null or empty");
    }

    SignedRequestsJavaHelper instance = new SignedRequestsJavaHelper();
    instance.endpoint = endpoint.toLowerCase();
    instance.awsAccessKeyId = awsAccessKeyId;
    instance.awsSecretKey = awsSecretKey;

    byte[] secretyKeyBytes = instance.awsSecretKey.getBytes(UTF8_CHARSET);
    instance.secretKeySpec = new SecretKeySpec(secretyKeyBytes, HMAC_SHA256_ALGORITHM);
    instance.mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
    instance.mac.init(instance.secretKeySpec);

    return instance;
}

From source file:com.todoroo.astrid.helper.AmazonRequestsHelper.java

/**
 * You must provide the three values below to initialize the helper.
 *
 * @param endpoint          Destination for the requests.
 * @param awsAccessKeyId    Your AWS Access Key ID
 * @param awsSecretKey      Your AWS Secret Key
 *//*  ww w . j a va 2  s  .c  o m*/
public static AmazonRequestsHelper getInstance(String endpoint, String awsAccessKeyId, String awsSecretKey)
        throws IllegalArgumentException, UnsupportedEncodingException, NoSuchAlgorithmException,
        InvalidKeyException {
    if (null == endpoint || endpoint.length() == 0) {
        throw new IllegalArgumentException("endpoint is null or empty");
    }
    if (null == awsAccessKeyId || awsAccessKeyId.length() == 0) {
        throw new IllegalArgumentException("awsAccessKeyId is null or empty");
    }
    if (null == awsSecretKey || awsSecretKey.length() == 0) {
        throw new IllegalArgumentException("awsSecretKey is null or empty");
    }

    AmazonRequestsHelper instance = new AmazonRequestsHelper();
    instance.endpoint = endpoint.toLowerCase();
    instance.awsAccessKeyId = awsAccessKeyId;
    instance.awsSecretKey = awsSecretKey;

    byte[] secretyKeyBytes = instance.awsSecretKey.getBytes(UTF8_CHARSET);
    instance.secretKeySpec = new SecretKeySpec(secretyKeyBytes, HMAC_SHA256_ALGORITHM);
    instance.mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
    instance.mac.init(instance.secretKeySpec);

    return instance;
}

From source file:com.melloware.jukes.ws.SignedRequestsHelper.java

/**
 * You must provide the three values below to initialize the helper.
 *  /*  www .j  av  a  2 s  . c  o  m*/
 * @param endpoint          Destination for the requests.
 * @param awsAccessKeyId    Your AWS Access Key ID
 * @param awsSecretKey      Your AWS Secret Key
 */
public static SignedRequestsHelper getInstance(String endpoint, String awsAccessKeyId, String awsSecretKey)
        throws IllegalArgumentException, UnsupportedEncodingException, NoSuchAlgorithmException,
        InvalidKeyException {
    if (null == endpoint || endpoint.length() == 0) {
        throw new IllegalArgumentException("endpoint is null or empty");
    }
    if (null == awsAccessKeyId || awsAccessKeyId.length() == 0) {
        throw new IllegalArgumentException("awsAccessKeyId is null or empty");
    }
    if (null == awsSecretKey || awsSecretKey.length() == 0) {
        throw new IllegalArgumentException("awsSecretKey is null or empty");
    }

    SignedRequestsHelper instance = new SignedRequestsHelper();
    instance.endpoint = endpoint.toLowerCase();
    instance.awsAccessKeyId = awsAccessKeyId;
    instance.awsSecretKey = awsSecretKey;
    byte[] secretyKeyBytes = instance.awsSecretKey.getBytes(UTF8_CHARSET);
    instance.secretKeySpec = new SecretKeySpec(secretyKeyBytes, HMAC_SHA256_ALGORITHM);
    instance.mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
    instance.mac.init(instance.secretKeySpec);

    return instance;
}

From source file:com.paperight.product.amazon.AmazonSignedRequestsHelper.java

/**
 * You must provide the three values below to initialize the helper.
 *  /*  w  w  w.  jav  a 2  s  .com*/
 * @param endpoint          Destination for the requests.
 * @param awsAccessKeyId    Your AWS Access Key ID
 * @param awsSecretKey      Your AWS Secret Key
 */
public static AmazonSignedRequestsHelper getInstance(String endpoint, String awsAccessKeyId,
        String awsSecretKey) throws IllegalArgumentException, UnsupportedEncodingException,
        NoSuchAlgorithmException, InvalidKeyException {
    if (null == endpoint || endpoint.length() == 0) {
        throw new IllegalArgumentException("endpoint is null or empty");
    }
    if (null == awsAccessKeyId || awsAccessKeyId.length() == 0) {
        throw new IllegalArgumentException("awsAccessKeyId is null or empty");
    }
    if (null == awsSecretKey || awsSecretKey.length() == 0) {
        throw new IllegalArgumentException("awsSecretKey is null or empty");
    }

    AmazonSignedRequestsHelper instance = new AmazonSignedRequestsHelper();
    instance.endpoint = endpoint.toLowerCase();
    instance.awsAccessKeyId = awsAccessKeyId;
    instance.awsSecretKey = awsSecretKey;

    byte[] secretyKeyBytes = instance.awsSecretKey.getBytes(UTF8_CHARSET);
    instance.secretKeySpec = new SecretKeySpec(secretyKeyBytes, HMAC_SHA256_ALGORITHM);
    instance.mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
    instance.mac.init(instance.secretKeySpec);

    return instance;
}

From source file:com.shiksha.apnagang.SignedItemSearchRequestHelper.java

/**
 * You must provide the three values below to initialize the helper.
 *  /*from  w  ww  . j  av a2s .c  om*/
 * @param endpoint          Destination for the requests.
 * @param awsAccessKeyId    Your AWS Access Key ID
 * @param awsSecretKey      Your AWS Secret Key
 */
public static SignedItemSearchRequestHelper getInstance(String endpoint, String awsAccessKeyId,
        String awsSecretKey) throws IllegalArgumentException, UnsupportedEncodingException,
        NoSuchAlgorithmException, InvalidKeyException {
    if (null == endpoint || endpoint.length() == 0) {
        throw new IllegalArgumentException("endpoint is null or empty");
    }
    if (null == awsAccessKeyId || awsAccessKeyId.length() == 0) {
        throw new IllegalArgumentException("awsAccessKeyId is null or empty");
    }
    if (null == awsSecretKey || awsSecretKey.length() == 0) {
        throw new IllegalArgumentException("awsSecretKey is null or empty");
    }

    SignedItemSearchRequestHelper instance = new SignedItemSearchRequestHelper();
    instance.endpoint = endpoint.toLowerCase();
    instance.awsAccessKeyId = awsAccessKeyId;
    instance.awsSecretKey = awsSecretKey;

    byte[] secretyKeyBytes = instance.awsSecretKey.getBytes(UTF8_CHARSET);
    instance.secretKeySpec = new SecretKeySpec(secretyKeyBytes, HMAC_SHA256_ALGORITHM);
    instance.mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
    instance.mac.init(instance.secretKeySpec);

    return instance;
}

From source file:controllers.DiscourseAuth.java

private static String checksum(SecretKeySpec key, String macData)
        throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(key);//from  ww w . j  a va 2 s.c  om
    byte[] doFinal = mac.doFinal(macData.getBytes(StandardCharsets.UTF_8));
    return Hex.encodeHexString(doFinal);
}

From source file:org.apache.xml.security.algorithms.implementations.IntegrityHmac.java

/**
 * Method IntegrityHmac//from  ww  w  . j  a va2s  . c  om
 *
 * @throws XMLSignatureException
 */
public IntegrityHmac() throws XMLSignatureException {
    String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
    if (log.isDebugEnabled()) {
        log.debug("Created IntegrityHmacSHA1 using " + algorithmID);
    }

    try {
        this.macAlgorithm = Mac.getInstance(algorithmID);
    } catch (java.security.NoSuchAlgorithmException ex) {
        Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };

        throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
    }
}

From source file:com.learnjava.restapi.SignedRequestsHelper.java

/**
 * You must provide the three values below to initialize the helper.
 *
 * @param endpoint Destination for the requests.
 * @param awsAccessKeyId Your AWS Access Key ID
 * @param awsSecretKey Your AWS Secret Key
 *///from w w w.j ava  2  s. c  om
public static SignedRequestsHelper getInstance(String endpoint, String awsAccessKeyId, String awsSecretKey,
        String associateTag) throws IllegalArgumentException, UnsupportedEncodingException,
        NoSuchAlgorithmException, InvalidKeyException {
    if (null == endpoint || endpoint.length() == 0) {
        throw new IllegalArgumentException("endpoint is null or empty");
    }
    if (null == awsAccessKeyId || awsAccessKeyId.length() == 0) {
        throw new IllegalArgumentException("awsAccessKeyId is null or empty");
    }
    if (null == awsSecretKey || awsSecretKey.length() == 0) {
        throw new IllegalArgumentException("awsSecretKey is null or empty");
    }

    SignedRequestsHelper instance = new SignedRequestsHelper();
    instance.endpoint = endpoint.toLowerCase();
    instance.awsAccessKeyId = awsAccessKeyId;
    instance.awsSecretKey = awsSecretKey;
    instance.associateTag = associateTag;

    byte[] secretyKeyBytes = instance.awsSecretKey.getBytes(UTF8_CHARSET);
    instance.secretKeySpec = new SecretKeySpec(secretyKeyBytes, HMAC_SHA256_ALGORITHM);
    instance.mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
    instance.mac.init(instance.secretKeySpec);

    return instance;
}