Code example for BigInteger

Methods: mod, modPow

0
     * Generates the server's credentials that are to be sent to the client. 
     * @return The server's public value to the client 
     */ 
    public BigInteger generateServerCredentials()
    { 
        BigInteger k = SRP6Util.calculateK(digest, N, g);
        this.b = selectPrivateValue();
        this.B = k.multiply(v).mod(N).add(g.modPow(b, N)).mod(N);
 
        return B;
    } 
 
    /** 
     * Processes the client's credentials. If valid the shared secret is generated and returned. 
     * @param clientA The client's credentials 
     * @return A shared secret BigInteger 
     * @throws CryptoException If client's credentials are invalid 
     */ 
    public BigInteger calculateSecret(BigInteger clientA) throws CryptoException
    { 
        this.A = SRP6Util.validatePublicValue(N, clientA);
        this.u = SRP6Util.calculateU(digest, N, A, B);
        this.S = calculateS();
 
        return S;
    } 
 
    protected BigInteger selectPrivateValue()
    { 
        return SRP6Util.generatePrivateValue(digest, N, g, random);        
    } 
 
    private BigInteger calculateS()
    { 
        return v.modPow(u, N).multiply(A).mod(N).modPow(b, N);