Refine search
r = new BigInteger(bytes); s = new BigInteger(bytes); params = dsaKey.getParams(); p = params.getP(); q = params.getQ(); g = params.getG(); y = ((DSAPublicKey) dsaKey).getY(); if (r.signum() != 1 || r.compareTo(q) != -1 || s.signum() != 1 || s.compareTo(q) != -1) { return false;
@Override public void init(int keySize) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(keySize, new SecureRandom()); KeyPair pair = keyGen.generateKeyPair(); _x = ((DSAPrivateKey) pair.getPrivate()).getX().toByteArray(); _y = ((DSAPublicKey) pair.getPublic()).getY().toByteArray(); DSAParams params = ((DSAKey) pair.getPrivate()).getParams(); _p = params.getP().toByteArray(); _q = params.getQ().toByteArray(); _g = params.getG().toByteArray(); }
/** * Get the key size for the given {@code Key}. * * @param key the key * @return the key size or -1 if the key size cannot be determined */ public static int getKeySize(final Key key) { if (key instanceof ECKey) { ECParameterSpec params = ((ECKey) key).getParams(); if (params != null) { return params.getOrder().bitLength(); } } else if (key instanceof DSAKey) { DSAParams params = ((DSAKey) key).getParams(); if (params != null) { return params.getP().bitLength(); } } else if (key instanceof RSAKey) { return ((RSAKey) key).getModulus().bitLength(); } return -1; }
/** * <p>Returns <code>true</code> if the designated object is an instance of * {@link DSAKey} and has the same DSS (Digital Signature Standard) parameter * values as this one.</p> * * @param obj the other non-null DSS key to compare to. * @return <code>true</code> if the designated object is of the same type and * value as this one. */ public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof DSAKey)) { return false; } DSAKey that = (DSAKey) obj; return p.equals(that.getParams().getP()) && q.equals(that.getParams().getQ()) && g.equals(that.getParams().getG()); }
/** * {@inheritDoc} */ protected void engineInitSign(Key privateKey, SecureRandom secureRandom) throws XMLSignatureException { if (!(privateKey instanceof PrivateKey)) { String supplied = null; if (privateKey != null) { supplied = privateKey.getClass().getName(); } String needed = PrivateKey.class.getName(); Object exArgs[] = { supplied, needed }; throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs); } try { if (secureRandom == null) { this.signatureAlgorithm.initSign((PrivateKey) privateKey); } else { this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom); } } catch (InvalidKeyException ex) { throw new XMLSignatureException(ex); } size = ((DSAKey)privateKey).getParams().getQ().bitLength(); }
/** * Attempt to acquire parameters of the given type from the given key. * * @param key the key (must not be {@code null}) * @param paramSpecClass the parameter specification class (must not be {@code null}) * @param <P> the parameter specification type * @return the parameters, or {@code null} if no known parameters of the given type are available */ public static <P extends AlgorithmParameterSpec> P getParameters(Key key, Class<P> paramSpecClass) { if (key instanceof Password) { final AlgorithmParameterSpec parameterSpec = ((Password) key).getParameterSpec(); return paramSpecClass.isInstance(parameterSpec) ? paramSpecClass.cast(parameterSpec) : null; } else if (key instanceof RSAKey && paramSpecClass.isAssignableFrom(RSAParameterSpec.class)) { return paramSpecClass.cast(new RSAParameterSpec((RSAKey) key)); } else if (key instanceof DSAKey && paramSpecClass.isAssignableFrom(DSAParams.class)) { return paramSpecClass.cast(((DSAKey) key).getParams()); } else if (key instanceof ECKey && paramSpecClass.isAssignableFrom(ECParameterSpec.class)) { return paramSpecClass.cast(((ECKey) key).getParams()); } else if (key instanceof DHKey && paramSpecClass.isAssignableFrom(DHParameterSpec.class)) { return paramSpecClass.cast(((DHKey) key).getParams()); } else if (key instanceof PBEKey && paramSpecClass.isAssignableFrom(PBEParameterSpec.class)) { final PBEKey pbeKey = (PBEKey) key; final byte[] salt = pbeKey.getSalt(); // TODO: we miss the IV here return salt == null ? null : paramSpecClass.cast(new PBEParameterSpec(salt, pbeKey.getIterationCount())); } else { return null; } }
public void init(int key_size) throws Exception{ KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(key_size, new SecureRandom()); KeyPair pair = keyGen.generateKeyPair(); PublicKey pubKey=pair.getPublic(); PrivateKey prvKey=pair.getPrivate(); x=((DSAPrivateKey)prvKey).getX().toByteArray(); y=((DSAPublicKey)pubKey).getY().toByteArray(); DSAParams params=((DSAKey)prvKey).getParams(); p=params.getP().toByteArray(); q=params.getQ().toByteArray(); g=params.getG().toByteArray(); } public byte[] getX(){return x;}
public int getKeySize() { if ( PublicKey.class.isAssignableFrom( key.getClass() ) ) { if ( RSAKey.class.isAssignableFrom( key.getClass() ) ) { return ( ( RSAKey ) key ).getModulus().bitLength(); } else if ( DSAKey.class.isAssignableFrom( key.getClass() ) ) { return ( ( DSAKey ) key ).getParams().getP().bitLength(); } else if ( DHKey.class.isAssignableFrom( key.getClass() ) ) { return ( ( DHKey ) key ).getParams().getP().bitLength(); } throw new CryptoFailure( "Unsupported PublicKey type" ); } throw new CryptoFailure( "Unsupported Key type" ); }
/** * Attempt to acquire parameters of the given type from the given key. * * @param key the key (must not be {@code null}) * @param paramSpecClass the parameter specification class (must not be {@code null}) * @param <P> the parameter specification type * @return the parameters, or {@code null} if no known parameters of the given type are available */ public static <P extends AlgorithmParameterSpec> P getParameters(Key key, Class<P> paramSpecClass) { if (key instanceof Password) { final AlgorithmParameterSpec parameterSpec = ((Password) key).getParameterSpec(); return paramSpecClass.isInstance(parameterSpec) ? paramSpecClass.cast(parameterSpec) : null; } else if (key instanceof RSAKey && paramSpecClass.isAssignableFrom(RSAParameterSpec.class)) { return paramSpecClass.cast(new RSAParameterSpec((RSAKey) key)); } else if (key instanceof DSAKey && paramSpecClass.isAssignableFrom(DSAParams.class)) { return paramSpecClass.cast(((DSAKey) key).getParams()); } else if (key instanceof ECKey && paramSpecClass.isAssignableFrom(ECParameterSpec.class)) { return paramSpecClass.cast(((ECKey) key).getParams()); } else if (key instanceof DHKey && paramSpecClass.isAssignableFrom(DHParameterSpec.class)) { return paramSpecClass.cast(((DHKey) key).getParams()); } else if (key instanceof PBEKey && paramSpecClass.isAssignableFrom(PBEParameterSpec.class)) { final PBEKey pbeKey = (PBEKey) key; final byte[] salt = pbeKey.getSalt(); // TODO: we miss the IV here return salt == null ? null : paramSpecClass.cast(new PBEParameterSpec(salt, pbeKey.getIterationCount())); } else { return null; } }
params = dsaKey.getParams(); p = params.getP(); q = params.getQ(); g = params.getG(); x = ((DSAPrivateKey) dsaKey).getX(); digestBI = new BigInteger(1, msgDigest.digest()); k = new BigInteger(1, randomBytes); if (k.compareTo(q) != -1) { continue;
public void init(int key_size) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(key_size, new SecureRandom()); KeyPair pair = keyGen.generateKeyPair(); PublicKey pubKey = pair.getPublic(); PrivateKey prvKey = pair.getPrivate(); x = ((DSAPrivateKey) prvKey).getX().toByteArray(); y = ((DSAPublicKey) pubKey).getY().toByteArray(); DSAParams params = ((DSAKey) prvKey).getParams(); p = params.getP().toByteArray(); q = params.getQ().toByteArray(); g = params.getG().toByteArray(); }
/** * {@inheritDoc} */ @Override public void injectReferenceValue(X509Certificate value) throws PolicyProcessException { int retVal = 0; this.certificate = value; final PublicKey pubKey = this.certificate.getPublicKey(); if (pubKey instanceof RSAKey) { retVal = ((RSAKey)pubKey).getModulus().bitLength(); } else if (pubKey instanceof DSAKey) { retVal = ((DSAKey)pubKey).getParams().getP().bitLength(); } else { // undertermined retVal = 0; } this.policyValue = PolicyValueFactory.getInstance(retVal); } }
/** * Attempt to acquire parameters of the given type from the given key. * * @param key the key (must not be {@code null}) * @param paramSpecClass the parameter specification class (must not be {@code null}) * @param <P> the parameter specification type * @return the parameters, or {@code null} if no known parameters of the given type are available */ public static <P extends AlgorithmParameterSpec> P getParameters(Key key, Class<P> paramSpecClass) { if (key instanceof Password) { final AlgorithmParameterSpec parameterSpec = ((Password) key).getParameterSpec(); return paramSpecClass.isInstance(parameterSpec) ? paramSpecClass.cast(parameterSpec) : null; } else if (key instanceof RSAKey && paramSpecClass.isAssignableFrom(RSAParameterSpec.class)) { return paramSpecClass.cast(new RSAParameterSpec((RSAKey) key)); } else if (key instanceof DSAKey && paramSpecClass.isAssignableFrom(DSAParams.class)) { return paramSpecClass.cast(((DSAKey) key).getParams()); } else if (key instanceof ECKey && paramSpecClass.isAssignableFrom(ECParameterSpec.class)) { return paramSpecClass.cast(((ECKey) key).getParams()); } else if (key instanceof DHKey && paramSpecClass.isAssignableFrom(DHParameterSpec.class)) { return paramSpecClass.cast(((DHKey) key).getParams()); } else if (key instanceof PBEKey && paramSpecClass.isAssignableFrom(PBEParameterSpec.class)) { final PBEKey pbeKey = (PBEKey) key; final byte[] salt = pbeKey.getSalt(); // TODO: we miss the IV here return salt == null ? null : paramSpecClass.cast(new PBEParameterSpec(salt, pbeKey.getIterationCount())); } else { return null; } }
r = new BigInteger(bytes); s = new BigInteger(bytes); params = dsaKey.getParams(); p = params.getP(); q = params.getQ(); g = params.getG(); y = ((DSAPublicKey) dsaKey).getY(); if (r.signum() != 1 || r.compareTo(q) != -1 || s.signum() != 1 || s.compareTo(q) != -1) { return false;
public void init(int key_size) throws Exception{ KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(key_size, new SecureRandom()); KeyPair pair = keyGen.generateKeyPair(); PublicKey pubKey=pair.getPublic(); PrivateKey prvKey=pair.getPrivate(); x=((DSAPrivateKey)prvKey).getX().toByteArray(); y=((DSAPublicKey)pubKey).getY().toByteArray(); DSAParams params=((DSAKey)prvKey).getParams(); p=params.getP().toByteArray(); q=params.getQ().toByteArray(); g=params.getG().toByteArray(); } public byte[] getX(){return x;}
/** * Get the key size for the given {@code Key}. * * @param key the key * @return the key size or -1 if the key size cannot be determined */ public static int getKeySize(final Key key) { if (key instanceof ECKey) { ECParameterSpec params = ((ECKey) key).getParams(); if (params != null) { return params.getOrder().bitLength(); } } else if (key instanceof DSAKey) { DSAParams params = ((DSAKey) key).getParams(); if (params != null) { return params.getP().bitLength(); } } else if (key instanceof RSAKey) { return ((RSAKey) key).getModulus().bitLength(); } return -1; }