List of usage examples for java.security.interfaces DSAPublicKey getY
public BigInteger getY();
From source file:org.cesecore.keys.util.KeyTools.java
/** * Gets the key length of supported keys * //from w w w . j ava 2 s.co m * @param pk * PublicKey used to derive the keysize * @return -1 if key is unsupported, otherwise a number >= 0. 0 usually means the length can not be calculated, for example if the key is an EC * key and the "implicitlyCA" encoding is used. */ public static int getKeyLength(final PublicKey pk) { int len = -1; if (pk instanceof RSAPublicKey) { final RSAPublicKey rsapub = (RSAPublicKey) pk; len = rsapub.getModulus().bitLength(); } else if (pk instanceof JCEECPublicKey) { final JCEECPublicKey ecpriv = (JCEECPublicKey) pk; final org.bouncycastle.jce.spec.ECParameterSpec spec = ecpriv.getParameters(); if (spec != null) { len = spec.getN().bitLength(); } else { // We support the key, but we don't know the key length len = 0; } } else if (pk instanceof BCECPublicKey) { final BCECPublicKey ecpriv = (BCECPublicKey) pk; final org.bouncycastle.jce.spec.ECParameterSpec spec = ecpriv.getParameters(); if (spec != null) { len = spec.getN().bitLength(); } else { // We support the key, but we don't know the key length len = 0; } } else if (pk instanceof ECPublicKey) { final ECPublicKey ecpriv = (ECPublicKey) pk; final java.security.spec.ECParameterSpec spec = ecpriv.getParams(); if (spec != null) { len = spec.getOrder().bitLength(); // does this really return something we expect? } else { // We support the key, but we don't know the key length len = 0; } } else if (pk instanceof DSAPublicKey) { final DSAPublicKey dsapub = (DSAPublicKey) pk; if (dsapub.getParams() != null) { len = dsapub.getParams().getP().bitLength(); } else { len = dsapub.getY().bitLength(); } } return len; }
From source file:org.cesecore.keys.util.KeyTools.java
/** * Print parameters of public part of a key. * /*from ww w . j a v a 2 s . co m*/ * @param publK * the key * @param ps * stream to print to. */ public static void printPublicKeyInfo(final PublicKey publK, final PrintStream ps) { if (publK instanceof RSAPublicKey) { ps.println("RSA key:"); final RSAPublicKey rsa = (RSAPublicKey) publK; ps.println(" modulus: " + rsa.getModulus().toString(16)); ps.println(" public exponent: " + rsa.getPublicExponent().toString(16)); return; } if (publK instanceof ECPublicKey) { ps.println("Elliptic curve key:"); final ECPublicKey ec = (ECPublicKey) publK; ps.println(" the affine x-coordinate: " + ec.getW().getAffineX().toString(16)); ps.println(" the affine y-coordinate: " + ec.getW().getAffineY().toString(16)); return; } if (publK instanceof DHPublicKey) { ps.println("DH key:"); final DHPublicKey dh = (DHPublicKey) publK; ps.println(" the public value y: " + dh.getY().toString(16)); return; } if (publK instanceof DSAPublicKey) { ps.println("DSA key:"); final DSAPublicKey dsa = (DSAPublicKey) publK; ps.println(" the public value y: " + dsa.getY().toString(16)); return; } }
From source file:org.ejbca.util.keystore.KeyTools.java
/** * Gets the key length of supported keys * @param pk PublicKey used to derive the keysize * @return -1 if key is unsupported, otherwise a number >= 0. 0 usually means the length can not be calculated, * for example if the key is an EC key and the "implicitlyCA" encoding is used. *///from w w w .j av a2 s .c om public static int getKeyLength(final PublicKey pk) { int len = -1; if (pk instanceof RSAPublicKey) { final RSAPublicKey rsapub = (RSAPublicKey) pk; len = rsapub.getModulus().bitLength(); } else if (pk instanceof JCEECPublicKey) { final JCEECPublicKey ecpriv = (JCEECPublicKey) pk; final org.bouncycastle.jce.spec.ECParameterSpec spec = ecpriv.getParameters(); if (spec != null) { len = spec.getN().bitLength(); } else { // We support the key, but we don't know the key length len = 0; } } else if (pk instanceof ECPublicKey) { final ECPublicKey ecpriv = (ECPublicKey) pk; final java.security.spec.ECParameterSpec spec = ecpriv.getParams(); if (spec != null) { len = spec.getOrder().bitLength(); // does this really return something we expect? } else { // We support the key, but we don't know the key length len = 0; } } else if (pk instanceof DSAPublicKey) { final DSAPublicKey dsapub = (DSAPublicKey) pk; if (dsapub.getParams() != null) { len = dsapub.getParams().getP().bitLength(); } else { len = dsapub.getY().bitLength(); } } return len; }