Example usage for java.security.spec DSAPrivateKeySpec getX

List of usage examples for java.security.spec DSAPrivateKeySpec getX

Introduction

In this page you can find the example usage for java.security.spec DSAPrivateKeySpec getX.

Prototype

public BigInteger getX() 

Source Link

Document

Returns the private key x .

Usage

From source file:MainClass.java

public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeySpecException {
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA");
    kpg.initialize(512);//  w ww  .j  av  a2s .c om
    KeyPair keys = kpg.genKeyPair();
    PrivateKey priKey = keys.getPrivate();
    PublicKey pubKey = keys.getPublic();
    KeyFactory kf = KeyFactory.getInstance("DSA");
    DSAPrivateKeySpec dsaPriKeySpec = (DSAPrivateKeySpec) kf.getKeySpec(priKey, DSAPrivateKeySpec.class);
    DSAPublicKeySpec dsaPubKeySpec = (DSAPublicKeySpec) kf.getKeySpec(pubKey, DSAPublicKeySpec.class);
    System.out.println("\nDSA Private Key");
    System.out.println("\nx = " + dsaPriKeySpec.getX());
    System.out.println("\nDSA Public Key");
    System.out.println("\ng = " + dsaPubKeySpec.getG());
    System.out.println("\np = " + dsaPubKeySpec.getP());
    System.out.println("\nq = " + dsaPubKeySpec.getQ());
    System.out.println("\ny = " + dsaPubKeySpec.getY());
}