Java 8 Mac - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Mac class.

This code example shows how to use the following methods:doFinal, getAlgorithm, init
    public byte[] calculateMac(byte[] pwd, byte[] data)
        throws CRMFException 
    { 
        try 
        { 
            mac.init(new SecretKeySpec(pwd, mac.getAlgorithm()));
 
            return mac.doFinal(data);
        } 
        catch (GeneralSecurityException e)
        { 
            throw new CRMFException("failure in setup: " + e.getMessage(), e);
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:doFinal, init
   */ 
  protected static byte[] createPassword(byte[] identifier, 
                                         SecretKey key) {
    Mac mac = threadLocalMac.get();
    try { 
      mac.init(key);
    } catch (InvalidKeyException ike) {
      throw new IllegalArgumentException("Invalid key to HMAC computation", 
                                         ike);
    } 
    return mac.doFinal(identifier);
  } 
   
  /** 
   * Convert the byte[] to a secret key 
   * @param key the byte[] to create a secret key from 
   * @return the secret key 
   */ 
  protected static SecretKey createSecretKey(byte[] key) {
    return new SecretKeySpec(key, DEFAULT_HMAC_ALGORITHM);
6
CodeRank
This code example shows how to use the following methods:doFinal, reset, update
                                                                    SecurityException { 
        Mac mac = currentMAC == null ? defaultMAC : currentMAC;
        if (mac == null) {
            throw new SecurityException("no key for mac calculation");
        } 
        mac.reset();
        mac.update(data, start, end - start + 1);
        mac.doFinal(data, end + 1);
    } 
 
    /** 
     * validate a mac that is at the end of a piece of byte array data 
     *  
     * @param data 
     *            to validate 
     * @param start 
     *            of the data - inclusive 
     * @param end 
     *            of the data - inlcusive, mac present after this 
     * @throws SecurityException 
6
CodeRank
This code example shows how to use the following methods:doFinal, update
        this.dataStr.writeInt(out.length); // Write length.
        this.dataStr.write(out); // Write encrypted data.
        this.dataStr.flush();
        final byte[] block = this.buffer.toByteArray();
        this.buffer.reset();
        this.mac.update(block);
        this.wrapped.write(block);
    } 
 
    /* 
     * (non-Javadoc) 
     * @see java.io.OutputStream#flush() 
     */ 
    @Override 
    public void flush() throws IOException 
    { 
        this.wrapped.flush();
    } 
 
    /* 

5
CodeRank
This code example shows how to use the following methods:doFinal
        mac.update(b, off, len);
    } 
 
    public byte[] getMac() 
    { 
        return mac.doFinal();
    } 
} 
5
CodeRank
This code example shows how to use the following methods:clone, doFinal, getMacLength, init, reset
        Security.removeProvider(mProv.getName());
    } 
     
    protected void checkResult(Mac mac) throws InvalidKeyException,
            InvalidAlgorithmParameterException { 
        assertEquals("Incorrect MacLength", mac.getMacLength(), 0);
        byte [] b = {(byte)0, (byte)0, (byte)0, (byte)0, (byte)0};
        SecretKeySpec scs = new SecretKeySpec(b, "SHA1");
        AlgParSpec parms = new AlgParSpec();
        tmpKey tKey = new tmpKey();
        mac.init(scs);        
        byte[] bb = mac.doFinal();
        assertEquals(bb.length, 0);
        mac.reset();
        bb = mac.doFinal();
        assertEquals(bb.length, 1);
        try { 
            mac.init(null);
            fail("InvalidKeyException should be thrown");
        } catch (InvalidKeyException e) {

5
CodeRank
This code example shows how to use the following methods:init, update
        // Read and decrypt the MAC key 
        final SecretKey macKey = new SecretKeySpec(this.inputCipher.doFinal(readBlock()), "HMACSHA1");
 
        // Set up HMAC 
        this.mac = Mac.getInstance("HMACSHA1");
        this.mac.init(macKey);
 
        // Always read a block ahead so we can intercept the HMAC block 
        this.nextDataBlock = readBlock(false);
    } 
 
    /** 
     * Reads the next block of data, adding it to the HMAC checksum. Strips the header recording the number of bytes in 
     * the block. 
     *  
     * @return the data block, or <code>null</code> if the end of the stream has been reached 
     * @throws IOException 
     *             Signals that an I/O exception has occurred. 
     */ 
    private byte[] readBlock() throws IOException 

5
CodeRank
This code example shows how to use the following methods:update
    } 
 
    /** @inheritDoc */ 
    public void write(byte[] arg0)  {
        super.write(arg0, 0, arg0.length);
        mac.update(arg0);
    } 
 
    /** @inheritDoc */ 
    public void write(int arg0) {
        super.write(arg0);
        mac.update((byte) arg0);
    } 
 
    /** @inheritDoc */ 
    public void write(byte[] arg0, int arg1, int arg2) {
        super.write(arg0, arg1, arg2);
        mac.update(arg0, arg1, arg2);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:doFinal, init
   */ 
  protected static byte[] createPassword(byte[] identifier, 
                                         SecretKey key) {
    Mac mac = threadLocalMac.get();
    try { 
      mac.init(key);
    } catch (InvalidKeyException ike) {
      throw new IllegalArgumentException("Invalid key to HMAC computation", 
                                         ike);
    } 
    return mac.doFinal(identifier);
  } 
   
  /** 
   * Convert the byte[] to a secret key 
   * @param key the byte[] to create a secret key from 
   * @return the secret key 
   */ 
  protected static SecretKey createSecretKey(byte[] key) {
    return new SecretKeySpec(key, DEFAULT_HMAC_ALGORITHM);
5
CodeRank
This code example shows how to use the following methods:doFinal
            return new MacOutputStream(mac);
        } 
 
        public byte[] getMac() 
        { 
            return mac.doFinal();
        } 
 
        public GenericKey getKey() 
        { 
            return new JceGenericKey(algorithmIdentifier, encKey);
        } 
 
        protected AlgorithmParameterSpec generateParameterSpec(ASN1ObjectIdentifier macOID, SecretKey encKey)
            throws CMSException 
        { 
            try 
            { 
                if (macOID.equals(PKCSObjectIdentifiers.RC2_CBC))
                { 
5
CodeRank

Related Java 8 Mac Questions & Answers:

See Code Examples for Java 8 Mac Methods: