Java 8 DSAParams - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DSAParams class.

This code example shows how to use the following methods:getG, getP, getQ
		DSAPublicKey pubKey = (DSAPublicKey) kp.getPublic();
 
		assertEquals(DSA_KEY_pub, pubKey.getY());
 
		DSAParams params = pubKey.getParams();
		assertEquals(params.getG(), DSA_KEY_G);
		assertEquals(params.getP(), DSA_KEY_P);
		assertEquals(params.getQ(), DSA_KEY_Q);
	} 
 
	public void testRecoverKeyPair_Rsa() throws Exception { 
		KeyPair kp = PubkeyUtils.recoverKeyPair(RSA_KEY_PKCS8);
 
		RSAPublicKey pubKey = (RSAPublicKey) kp.getPublic();
 
		assertEquals(RSA_KEY_N, pubKey.getModulus());
		assertEquals(RSA_KEY_E, pubKey.getPublicExponent());
	} 
 
	public void testRecoverKeyPair_Ec() throws Exception { 
7
CodeRank
This code example shows how to use the following methods:getG, getP, getQ
this.publicKey = key;
        if (key instanceof DSAPublicKey) {
            DSAPublicKey dkey = (DSAPublicKey) key;
            DSAParams params = dkey.getParams();
            p = new DOMCryptoBinary(params.getP());
            q = new DOMCryptoBinary(params.getQ());
            g = new DOMCryptoBinary(params.getG());
            y = new DOMCryptoBinary(dkey.getY());
        } else if (key instanceof RSAPublicKey) {
            RSAPublicKey rkey = (RSAPublicKey) key;
            exponent = new DOMCryptoBinary(rkey.getPublicExponent());
            modulus = new DOMCryptoBinary(rkey.getModulus());
        } else { 
            throw new KeyException("unsupported key algorithm: " +
                key.getAlgorithm());
        } 
    } 
 
    /** 
6
CodeRank
This code example shows how to use the following methods:getG, getP, getQ
		DSAPublicKey pubKey = (DSAPublicKey) kp.getPublic();
 
		assertEquals(DSA_KEY_pub, pubKey.getY());
 
		DSAParams params = pubKey.getParams();
		assertEquals(params.getG(), DSA_KEY_G);
		assertEquals(params.getP(), DSA_KEY_P);
		assertEquals(params.getQ(), DSA_KEY_Q);
	} 
 
	public void testRecoverKeyPair_Rsa() throws Exception { 
		KeyPair kp = PubkeyUtils.recoverKeyPair(RSA_KEY_PKCS8);
 
		RSAPublicKey pubKey = (RSAPublicKey) kp.getPublic();
 
		assertEquals(RSA_KEY_N, pubKey.getModulus());
		assertEquals(RSA_KEY_E, pubKey.getPublicExponent());
	} 
 
	public void testRecoverKeyPair_Ec() throws Exception { 
7
CodeRank
This code example shows how to use the following methods:getG, getP, getQ
		TypesWriter tw = new TypesWriter();
 
		tw.writeString("ssh-dss");
 
		DSAParams params = pk.getParams();
		tw.writeMPInt(params.getP());
		tw.writeMPInt(params.getQ());
		tw.writeMPInt(params.getG());
		tw.writeMPInt(pk.getY());
 
		return tw.getBytes();
	} 
 
	/** 
	 * Convert from Java's signature ASN.1 encoding to the SSH spec. 
	 * <p> 
	 * Java ASN.1 encoding: 
	 * <pre> 
	 * SEQUENCE ::= { 
	 *    r INTEGER, 
6
CodeRank
This code example shows how to use the following methods:getG, getP, getQ
This code example shows how to use the following methods:getG, getP, getQ
This code example shows how to use the following methods:getG, getP, getQ
 
                    y = publicKey.getY();
 
                    DSAParams params = publicKey.getParams();
 
                    p = params.getP();
                    q = params.getQ();
                    g = params.getG();
 
                    return (T) (new DSAPublicKeySpec(y, p, q, g));
                } 
 
                if (keySpec.equals(X509EncodedKeySpec.class)) {
                    return (T) (new X509EncodedKeySpec(key.getEncoded()));
                } 
 
                throw new InvalidKeySpecException("'keySpec' is neither DSAPublicKeySpec nor X509EncodedKeySpec");
            } 
        } 
        throw new InvalidKeySpecException("'key' is neither DSAPublicKey nor DSAPrivateKey");
6
CodeRank
This code example shows how to use the following methods:getG, getP, getQ
        key = (DSAKey) gen.generateKeyPair().getPublic();
        assertDSAParamsEquals(param, key.getParams());
    } 
 
    private void assertDSAParamsEquals(DSAParams expected, DSAParams actual) {
        assertEquals("P differ", expected.getP(), actual.getP());
        assertEquals("Q differ", expected.getQ(), actual.getQ());
        assertEquals("G differ", expected.getG(), actual.getG());
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getG, getP, getQ
        } 
 
        ensureReadParams(); 
 
        DSAParams other = (DSAParams) o;
        return g.equals(other.getG()) && p.equals(other.getP()) && q.equals(other.getQ());
    } 
 
    @Override 
    public int hashCode() { 
        ensureReadParams(); 
 
        return g.hashCode() ^ p.hashCode() ^ q.hashCode();
    } 
 
    @Override 
    public String toString() {
        ensureReadParams(); 
 
        final StringBuilder sb = new StringBuilder("OpenSSLDSAParams{");
6
CodeRank
This code example shows how to use the following methods:getG, getP, getQ
        DSAPublicKey key = (DSAPublicKey) keyPairGenerator.genKeyPair()
                .getPublic();
        DSAParams params = key.getParams();
 
        KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
        keyPair.initialize(new DSAParameterSpec(params.getP(), params.getQ(),
                params.getG()));
    } 
 
    /** 
     * java.security.KeyPairGenerator#initialize(java.security.spec.AlgorithmParameterSpec, 
     *        java.security.SecureRandom) 
     */ 
    public void test_initializeLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom() 
            throws Exception {
        // create DSAParams 
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
        keyPairGenerator.initialize(1024);
        DSAPublicKey key = (DSAPublicKey) keyPairGenerator.genKeyPair()
                .getPublic();
6
CodeRank
See Code Examples for Java 8 DSAParams Methods: