Example usage for org.bouncycastle.crypto.agreement.srp SRP6Client init

List of usage examples for org.bouncycastle.crypto.agreement.srp SRP6Client init

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.agreement.srp SRP6Client init.

Prototype

public void init(BigInteger N, BigInteger g, Digest digest, SecureRandom random) 

Source Link

Document

Initialises the client to begin new authentication attempt

Usage

From source file:org.forgerock.openicf.framework.remote.SecurityUtil.java

License:CDDL license

/**
 * Verifies the client and server secret.
 *
 * @param username     user name (aka "identity")
 * @param password     password//from   ww  w . j a  v  a2  s .  c o m
 * @param verification
 * @param random       the source of randomness for this generator
 * @param params       group parameters (prime, generator)
 * @return true if client and server secret is equals
 * @throws CryptoException If client or server's credentials are invalid
 */
public static boolean checkMutualVerification(String username, String password,
        Pair<String, byte[]> verification, SecureRandom random, SRPGroupParameter params)
        throws CryptoException {

    byte[] I = username.getBytes();
    byte[] P = password.getBytes();
    byte[] s = verification.second;
    BigInteger v = new BigInteger(verification.first, 16);

    SRP6Client client = new SRP6Client();
    client.init(params.N, params.g, new SHA256Digest(), random);

    SRP6Server server = new SRP6Server();
    server.init(params.N, params.g, v, new SHA256Digest(), random);

    BigInteger A = client.generateClientCredentials(s, I, P);
    BigInteger B = server.generateServerCredentials();

    BigInteger clientS = client.calculateSecret(B);
    BigInteger serverS = server.calculateSecret(A);

    return clientS.equals(serverS);
}