DSAKeyFactoryImplpublic class DSAKeyFactoryImpl extends KeyFactorySpi
Methods Summary |
---|
protected java.security.PrivateKey | engineGeneratePrivate(java.security.spec.KeySpec keySpec)The method generates a DSAPrivateKey object from the provided key specification.
if (keySpec != null) {
if (keySpec instanceof DSAPrivateKeySpec) {
return new DSAPrivateKeyImpl((DSAPrivateKeySpec) keySpec);
}
if (keySpec instanceof PKCS8EncodedKeySpec) {
return new DSAPrivateKeyImpl((PKCS8EncodedKeySpec) keySpec);
}
}
throw new InvalidKeySpecException(Messages.getString("security.19C")); //$NON-NLS-1$
| protected java.security.PublicKey | engineGeneratePublic(java.security.spec.KeySpec keySpec)The method generates a DSAPublicKey object from the provided key specification.
if (keySpec != null) {
if (keySpec instanceof DSAPublicKeySpec) {
return new DSAPublicKeyImpl((DSAPublicKeySpec) keySpec);
}
if (keySpec instanceof X509EncodedKeySpec) {
return new DSAPublicKeyImpl((X509EncodedKeySpec) keySpec);
}
}
throw new InvalidKeySpecException(Messages.getString("security.19D")); //$NON-NLS-1$
| protected T | engineGetKeySpec(java.security.Key key, java.lang.Class keySpec)The method returns a specification (key material) of the given key object.
'keySpec' identifies the specification class
in which the key material should be returned.
If it is DSAPublicKeySpec.class, the key material should be returned
in an instance of the DSAPublicKeySpec class;
if it is DSAPrivateKeySpec.class, the key material should be returned
in an instance of the DSAPrivateKeySpec class.
BigInteger p, q, g, x, y;
if (key != null) {
if (keySpec == null) {
throw new NullPointerException(Messages
.getString("security.19E")); //$NON-NLS-1$
}
if (key instanceof DSAPrivateKey) {
DSAPrivateKey privateKey = (DSAPrivateKey) key;
if (keySpec.equals(DSAPrivateKeySpec.class)) {
x = privateKey.getX();
DSAParams params = privateKey.getParams();
p = params.getP();
q = params.getQ();
g = params.getG();
return (T) (new DSAPrivateKeySpec(x, p, q, g));
}
if (keySpec.equals(PKCS8EncodedKeySpec.class)) {
return (T) (new PKCS8EncodedKeySpec(key.getEncoded()));
}
throw new InvalidKeySpecException(Messages
.getString("security.19C")); //$NON-NLS-1$
}
if (key instanceof DSAPublicKey) {
DSAPublicKey publicKey = (DSAPublicKey) key;
if (keySpec.equals(DSAPublicKeySpec.class)) {
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(Messages
.getString("security.19D")); //$NON-NLS-1$
}
}
throw new InvalidKeySpecException(Messages.getString("security.19F")); //$NON-NLS-1$
| protected java.security.Key | engineTranslateKey(java.security.Key key)The method generates a DSAPublicKey object from the provided key.
if (key != null) {
if (key instanceof DSAPrivateKey) {
DSAPrivateKey privateKey = (DSAPrivateKey) key;
DSAParams params = privateKey.getParams();
try {
return engineGeneratePrivate(new DSAPrivateKeySpec(
privateKey.getX(), params.getP(), params.getQ(),
params.getG()));
} catch (InvalidKeySpecException e) {
// Actually this exception shouldn't be thrown
throw new InvalidKeyException(Messages.getString(
"security.1A0", e)); //$NON-NLS-1$
}
}
if (key instanceof DSAPublicKey) {
DSAPublicKey publicKey = (DSAPublicKey) key;
DSAParams params = publicKey.getParams();
try {
return engineGeneratePublic(new DSAPublicKeySpec(publicKey
.getY(), params.getP(), params.getQ(), params
.getG()));
} catch (InvalidKeySpecException e) {
// Actually this exception shouldn't be thrown
throw new InvalidKeyException(Messages.getString(
"security.1A1", e)); //$NON-NLS-1$
}
}
}
throw new InvalidKeyException(Messages.getString("security.19F")); //$NON-NLS-1$
|
|