Package javax.crypto

Examples of javax.crypto.Mac.update()


    try {
      SecretKey secretKey = new SecretKeySpec(Base64.decode(sharedSecret), algorithm);
      Mac mac = Mac.getInstance(algorithm);
      mac.init(secretKey);
      mac.update(data);
      return Base64.encode(mac.doFinal());
    } catch (NoSuchAlgorithmException e) {
      throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    } catch (InvalidKeyException e) {
      throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
View Full Code Here


            if (macName.equalsIgnoreCase("TMMH16"))
              mac1.init(null, params);
            else
              mac1.init(new SecretKeySpec(kb, macName), params);

            mac1.update(abc); // start with abc
            mac2 = (Mac) mac1.clone(); // now clone it

            ba1 = mac1.doFinal(in); // now finish both with in
            ba2 = mac2.doFinal(in);
View Full Code Here

 
  public String generateCookie(String username) throws Exception{
      SecretKeySpec key = new SecretKeySpec(secret.getBytes(), "SHA");
      Mac mac = Mac.getInstance("HmacSHA1");
      mac.init(key);
      mac.update(username.getBytes());
      byte[] result = (mac.doFinal());
      String blah = "0123456789abcdef";
     
      String resultString = "";
      for (int i = 0; i < result.length; i++){
View Full Code Here

    String auth = "";
    SecretKeySpec key = new SecretKeySpec(secret.getBytes(), "SHA");
    try {
      Mac mac = Mac.getInstance("HmacSHA1");
      mac.init(key);
      mac.update(username.getBytes());
      byte[] result = (mac.doFinal());
     
      String charmap = "0123456789abcdef";
      for (int i = 0; i < result.length; i++) {
        int first = (result[i] >> 4) & 0x0f;
View Full Code Here

          SecretKey sk = new SecretKeySpec(currentKey,
              sa.getJCEAlgorithmString());

          Mac m = Mac.getInstance("HmacSHA1");
          m.init(sk);
          m.update(sASLPrepedPassword.getBytes("ISO8859-1"));
          byte[] mac = m.doFinal();
          for(int i=0;i<mac.length;i++){
               if(keyIndex < keylength){
                 finalKey[keyIndex] = mac[i];
                 keyIndex++;
View Full Code Here

        byte[] protectedBytes = ret.getProtectedBytes();
        Mac mac = Mac.getInstance(macOid, "BC");
        SecretKey key = new SecretKeySpec(basekey, macOid);
        mac.init(key);
        mac.reset();
        mac.update(protectedBytes, 0, protectedBytes.length);
        byte[] out = mac.doFinal();
        DERBitString bs = new DERBitString(out);

        // Finally store the protection bytes in the msg
        ret.setProtection(bs);
View Full Code Here

            String macOid = macAlg.getObjectId().getId();
            Mac mac = Mac.getInstance(macOid, "BC");
            SecretKey key = new SecretKeySpec(basekey, macOid);
            mac.init(key);
            mac.reset();
            mac.update(protectedBytes, 0, protectedBytes.length);
            byte[] out = mac.doFinal();
            // My out should now be the same as the protection bits
            byte[] pb = protection.getBytes();
            boolean ret = Arrays.equals(out, pb);
            assertTrue(ret);
View Full Code Here

                final byte[] protectedBytes = ret.getProtectedBytes();
                final Mac mac = Mac.getInstance(macOid, this.bcProvider);
                final SecretKey key = new SecretKeySpec(basekey, macOid);
                mac.init(key);
                mac.reset();
                mac.update(protectedBytes, 0, protectedBytes.length);
                final byte[] out = mac.doFinal();
                final DERBitString bs = new DERBitString(out);

                // Finally store the protection bytes in the msg
                ret.setProtection(bs);
View Full Code Here

                final Mac mac = Mac.getInstance(macOid, this.bcProvider);
                mac.init(key);
                mac.reset();
                final byte[] protectedBytes = respObject.getProtectedBytes();
                final DERBitString protection = respObject.getProtection();
                mac.update(protectedBytes, 0, protectedBytes.length);
                byte[] out = mac.doFinal();
                // My out should now be the same as the protection bits
                byte[] pb = protection.getBytes();
                if ( !Arrays.equals(out, pb) ) {
                    StressTest.this.performanceTest.getLog().error("Wrong PBE hash");
View Full Code Here

    private static String signRequest(String request, String key) {
        try {
            Mac mac = Mac.getInstance("HmacSHA1");
            SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacSHA1");
            mac.init(keySpec);
            mac.update(request.getBytes());
            byte[] encryptedBytes = mac.doFinal();
            return URLEncoder.encode(Base64.encodeBase64String(encryptedBytes), "UTF-8");
        } catch (Exception ex) {
            s_logger.error(ex.getMessage());
            return null;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.