Package javax.crypto

Examples of javax.crypto.Mac


            // Acquire an HMAC/SHA1 from the raw key bytes.
            SecretKeySpec signingKey=
                    new SecretKeySpec(awsSecretAccessKey.getBytes(), HMAC_SHA1_ALGORITHM);

            // Acquire the MAC instance and initialize with the signing key.
            Mac mac=null;
            try {
                mac=Mac.getInstance(HMAC_SHA1_ALGORITHM);
            }
            catch(NoSuchAlgorithmException e) {
                // should not happen
                throw new RuntimeException("Could not find sha1 algorithm", e);
            }
            try {
                mac.init(signingKey);
            }
            catch(InvalidKeyException e) {
                // also should not happen
                throw new RuntimeException("Could not initialize the MAC algorithm", e);
            }

            // Compute the HMAC on the digest, and set it.
            String b64=Base64.encodeBytes(mac.doFinal(canonicalString.getBytes()));

            if(urlencode) {
                return urlencode(b64);
            }
            else {
View Full Code Here


  public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
     
      try {
          SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
          Mac mac = Mac.getInstance("HmacSHA1");
          mac.init(signingKey);
   
          byte[] rawHmac = mac.doFinal(data);
   
          return encodeBase64(rawHmac);
         
      } catch (NoSuchAlgorithmException nsae) {
          throw new IOException("required algorithm HmacSHA1 is not supported by environment: " + nsae.toString());
View Full Code Here

    protected byte[] sign(byte[] data) throws AssociationException
    {
        try
        {
            String algorithm = _macKey.getAlgorithm();
            Mac mac = Mac.getInstance(algorithm);

            mac.init(_macKey);

            return mac.doFinal(data);
        }
        catch (GeneralSecurityException e)
        {
            throw new AssociationException("Cannot sign!", e);
        }
View Full Code Here

  public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
     
      try {
          SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
          Mac mac = Mac.getInstance("HmacSHA1");
          mac.init(signingKey);
   
          byte[] rawHmac = mac.doFinal(data);
   
          return encodeBase64(rawHmac);
         
      } catch (NoSuchAlgorithmException nsae) {
          throw new IOException("required algorithm HmacSHA1 is not supported by environment: " + nsae.toString());
View Full Code Here

    public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
       
        try {
            SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(signingKey);
   
            byte[] rawHmac = mac.doFinal(data);
   
            return encodeBase64(rawHmac);
           
        } catch (NoSuchAlgorithmException nsae) {
            throw new IOException("required algorithm HmacSHA1 is not supported by environment: " + nsae.toString());
View Full Code Here

  public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
     
      try {
          SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
          Mac mac = Mac.getInstance("HmacSHA1");
          mac.init(signingKey);
   
          byte[] rawHmac = mac.doFinal(data);
   
          return encodeBase64(rawHmac);
         
      } catch (NoSuchAlgorithmException nsae) {
          throw new IOException("required algorithm HmacSHA1 is not supported by environment: " + nsae.toString());
View Full Code Here

    public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
       
        try {
            SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(signingKey);
   
            byte[] rawHmac = mac.doFinal(data);
   
            return encodeBase64(rawHmac);
           
        } catch (NoSuchAlgorithmException nsae) {
            throw new IOException("required algorithm HmacSHA1 is not supported by environment: " + nsae.toString());
View Full Code Here

  public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
     
      try {
          SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
          Mac mac = Mac.getInstance("HmacSHA1");
          mac.init(signingKey);
   
          byte[] rawHmac = mac.doFinal(data);
   
          return encodeBase64(rawHmac);
         
      } catch (NoSuchAlgorithmException nsae) {
          throw new IOException("required algorithm HmacSHA1 is not supported by environment: " + nsae.toString());
View Full Code Here

        try {
            this.macAlgorithm.init(secretKey);
        } catch (InvalidKeyException ex) {
            // reinstantiate Mac object to work around bug in JDK
            // see: http://bugs.sun.com/view_bug.do?bug_id=4953555
            Mac mac = this.macAlgorithm;
            try {
                this.macAlgorithm = Mac.getInstance(macAlgorithm.getAlgorithm());
            } catch (Exception e) {
                // this shouldn't occur, but if it does, restore previous Mac
                if (log.isDebugEnabled()) {
View Full Code Here

        /**
         * Make sure that we can generate the  Mac.
         */
        try {
            Mac mac = Mac.getInstance(algorithm);
            mac.init(key);
        } catch (NoSuchAlgorithmException e) {
            assert false : "Should never have reached here";
        } catch (InvalidKeyException e) {
            assert false : "Should never have reached here";
        }
View Full Code Here

TOP

Related Classes of javax.crypto.Mac

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.