Android HMac Hash derivePKCS5S2Helper(Mac hMac, byte[] P, byte[] S, int c, byte[] iBuf, byte[] out, int outOff)

Here you can find the source of derivePKCS5S2Helper(Mac hMac, byte[] P, byte[] S, int c, byte[] iBuf, byte[] out, int outOff)

Description

derive PKCSS Helper

License

Open Source License

Declaration

private static void derivePKCS5S2Helper(Mac hMac, byte[] P, byte[] S,
            int c, byte[] iBuf, byte[] out, int outOff)
            throws GeneralSecurityException 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

import javax.crypto.Mac;

import javax.crypto.spec.SecretKeySpec;

import java.security.*;

public class Main {
    private static void derivePKCS5S2Helper(Mac hMac, byte[] P, byte[] S,
            int c, byte[] iBuf, byte[] out, int outOff)
            throws GeneralSecurityException {
        byte[] state = new byte[hMac.getMacLength()];
        SecretKeySpec param = new SecretKeySpec(P, "SHA1");
        hMac.init(param);//from w  ww . j a  va 2  s. co  m
        if (S != null) {
            hMac.update(S, 0, S.length);
        }
        hMac.update(iBuf, 0, iBuf.length);
        hMac.doFinal(state, 0);
        System.arraycopy(state, 0, out, outOff, state.length);
        if (c == 0) {
            throw new IllegalArgumentException(
                    "iteration count must be at least 1.");
        }
        for (int count = 1; count < c; count++) {
            hMac.init(param);
            hMac.update(state, 0, state.length);
            hMac.doFinal(state, 0);
            for (int j = 0; j != state.length; j++) {
                out[outOff + j] ^= state[j];
            }
        }
    }
}

Related

  1. getHmac(String[] args, String key)
  2. hmacSign(String aValue, String aKey)