Java 类org.bouncycastle.crypto.generators.PKCS5S1ParametersGenerator 实例源码

项目:irma_future_id    文件:GOST3411DigestTest.java   
public static void main(
    String[]    args)
{
    HMac gMac = new HMac(new GOST3411Digest(GOST28147Engine.getSBox("D-Test")));

    gMac.init(new KeyParameter(PKCS5S1ParametersGenerator.PKCS5PasswordToUTF8Bytes("Boss".toCharArray())));
    byte[] iBuf = new byte[4];
    byte[] data = Hex.decode("b5d78fa546ba645c");

    gMac.update(data, 0, data.length);
    byte[] mac = new byte[gMac.getMacSize()];

    int pos = 3;
    while (++iBuf[pos] == 0)
    {
        --pos;
    }
    gMac.update(iBuf, 0, iBuf.length);

    gMac.doFinal(mac, 0);

    System.err.println(mac.length + " " + new String(Hex.encode(mac)));

    PKCS5S2ParametersGenerator pGen = new PKCS5S2ParametersGenerator(new GOST3411Digest());

    pGen.init(PKCS5S1ParametersGenerator.PKCS5PasswordToUTF8Bytes("1".toCharArray()), data, 2048);

    KeyParameter kp = (KeyParameter)pGen.generateDerivedMacParameters(256);

    System.err.println(kp.getKey().length + " " + new String(Hex.encode(kp.getKey())));

    runTest(new GOST3411DigestTest());
}
项目:bc-java    文件:GOST3411DigestTest.java   
public static void main(
    String[]    args)
{
    HMac gMac = new HMac(new GOST3411Digest(GOST28147Engine.getSBox("D-Test")));

    gMac.init(new KeyParameter(PKCS5S1ParametersGenerator.PKCS5PasswordToUTF8Bytes("Boss".toCharArray())));
    byte[] iBuf = new byte[4];
    byte[] data = Hex.decode("b5d78fa546ba645c");

    gMac.update(data, 0, data.length);
    byte[] mac = new byte[gMac.getMacSize()];

    int pos = 3;
    while (++iBuf[pos] == 0)
    {
        --pos;
    }
    gMac.update(iBuf, 0, iBuf.length);

    gMac.doFinal(mac, 0);

    System.err.println(mac.length + " " + new String(Hex.encode(mac)));

    PKCS5S2ParametersGenerator pGen = new PKCS5S2ParametersGenerator(new GOST3411Digest());

    pGen.init(PKCS5S1ParametersGenerator.PKCS5PasswordToUTF8Bytes("1".toCharArray()), data, 2048);

    KeyParameter kp = (KeyParameter)pGen.generateDerivedMacParameters(256);

    System.err.println(kp.getKey().length + " " + new String(Hex.encode(kp.getKey())));

    runTest(new GOST3411DigestTest());
}
项目:gwt-crypto    文件:GOST3411DigestTest.java   
public void performTest()
{
    super.performTest();

    millionATest(million_a_digest);

    HMac gMac = new HMac(new GOST3411Digest());

    gMac.init(new KeyParameter(PKCS5S1ParametersGenerator.PKCS5PasswordToUTF8Bytes("1".toCharArray())));

    byte[] data = "fred".getBytes();

    gMac.update(data, 0, data.length);
    byte[] mac = new byte[gMac.getMacSize()];

    gMac.doFinal(mac, 0);

    if (!Arrays.areEqual(Hex.decode("e9f98610cfc80084462b175a15d2b4ec10b2ab892eae5a6179d572d9b1db6b72"), mac))
    {
        fail("mac calculation failed.");
    }
}
项目:immediatecrypt    文件:AESFacadeImpl.java   
protected ParametersWithIV createDecryptionParameters(String password,
        String salt, byte[] iv) {

    byte[] passwordBytes = password.getBytes(Charsets.UTF_8);
    byte[] saltBytes = salt.getBytes(Charsets.UTF_8);

    PKCS5S1ParametersGenerator keyGenerator = new PKCS5S1ParametersGenerator(
            new SHA512Digest());
    keyGenerator.init(passwordBytes, saltBytes, PBE_ITERATION_COUNT);

    KeyParameter params =
            (KeyParameter) keyGenerator.generateDerivedParameters(KEY_SIZE);

    return new ParametersWithIV(params, iv);

}
项目:Java-Security    文件:PBKDF1KeyGenerator.java   
/** {@inheritDoc} */
protected PBEParametersGenerator newParamGenerator() {
    return new PKCS5S1ParametersGenerator(digest.getDigest());
}
项目:irma_future_id    文件:GOST3411DigestTest.java   
public void performTest()
{
    super.performTest();

    millionATest(million_a_digest);

    HMac gMac = new HMac(new GOST3411Digest());

    gMac.init(new KeyParameter(PKCS5S1ParametersGenerator.PKCS5PasswordToUTF8Bytes("1".toCharArray())));

    byte[] data = "fred".getBytes();

    gMac.update(data, 0, data.length);
    byte[] mac = new byte[gMac.getMacSize()];

    gMac.doFinal(mac, 0);
    System.err.println("e080de3bde792327a6cccfa5dfd51e72b6829baa88d8130ed1a48822873fc7f6");
    System.err.println(new String(Hex.encode(mac)));
}
项目:bc-java    文件:GOST3411DigestTest.java   
public void performTest()
{
    super.performTest();

    millionATest(million_a_digest);

    HMac gMac = new HMac(new GOST3411Digest());

    gMac.init(new KeyParameter(PKCS5S1ParametersGenerator.PKCS5PasswordToUTF8Bytes("1".toCharArray())));

    byte[] data = "fred".getBytes();

    gMac.update(data, 0, data.length);
    byte[] mac = new byte[gMac.getMacSize()];

    gMac.doFinal(mac, 0);
    System.err.println("e080de3bde792327a6cccfa5dfd51e72b6829baa88d8130ed1a48822873fc7f6");
    System.err.println(new String(Hex.encode(mac)));
}
项目:immediatecrypt    文件:AESFacadeImpl.java   
protected ParametersWithIV createEncryptionParameters(String password, String salt) {

        byte[] passwordBytes = password.getBytes(Charsets.UTF_8);
        byte[] saltBytes = salt.getBytes(Charsets.UTF_8);

        PKCS5S1ParametersGenerator keyGenerator = new PKCS5S1ParametersGenerator(
                new SHA512Digest());
        keyGenerator.init(passwordBytes, saltBytes, PBE_ITERATION_COUNT);

        ParametersWithIV params =
                (ParametersWithIV) keyGenerator.generateDerivedParameters(KEY_SIZE, IV_SIZE);

        return params;

    }