Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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);
        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];
            }
        }
    }
}