/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* DH KeyFactory implemenation.
*
* @author Andreas Sterbenz
* @since 1.5
*/
}
try {
if (key instanceof DHPublicKey) {
return generatePublic(
);
// let SunJCE provider parse for us, then recurse
try {
return implTranslatePublicKey(key);
} catch (GeneralSecurityException e) {
throw new InvalidKeyException("Could not translate key", e);
}
} else {
throw new InvalidKeyException("PublicKey must be instance "
+ "of DHPublicKey or have X.509 encoding");
}
} catch (PKCS11Exception e) {
throw new InvalidKeyException("Could not create DH public key", e);
}
}
throws InvalidKeyException {
try {
if (key instanceof DHPrivateKey) {
return generatePrivate(
);
// let SunJCE provider parse for us, then recurse
try {
return implTranslatePrivateKey(key);
} catch (GeneralSecurityException e) {
throw new InvalidKeyException("Could not translate key", e);
}
} else {
throw new InvalidKeyException("PrivateKey must be instance "
+ "of DHPrivateKey or have PKCS#8 encoding");
}
} catch (PKCS11Exception e) {
throw new InvalidKeyException("Could not create DH private key", e);
}
}
// see JCA spec
throws InvalidKeySpecException {
token.ensureValid();
if (keySpec instanceof X509EncodedKeySpec) {
try {
return implTranslatePublicKey(key);
} catch (GeneralSecurityException e) {
throw new InvalidKeySpecException
("Could not create DH public key", e);
}
}
if (keySpec instanceof DHPublicKeySpec == false) {
throw new InvalidKeySpecException("Only DHPublicKeySpec and "
+ "X509EncodedKeySpec supported for DH public keys");
}
try {
return generatePublic(
);
} catch (PKCS11Exception e) {
throw new InvalidKeySpecException
("Could not create DH public key", e);
}
}
// see JCA spec
throws InvalidKeySpecException {
token.ensureValid();
if (keySpec instanceof PKCS8EncodedKeySpec) {
try {
return implTranslatePrivateKey(key);
} catch (GeneralSecurityException e) {
throw new InvalidKeySpecException
("Could not create DH private key", e);
}
}
if (keySpec instanceof DHPrivateKeySpec == false) {
throw new InvalidKeySpecException("Only DHPrivateKeySpec and "
+ "PKCS8EncodedKeySpec supported for DH private keys");
}
try {
return generatePrivate(
);
} catch (PKCS11Exception e) {
throw new InvalidKeySpecException
("Could not create DH private key", e);
}
}
throws PKCS11Exception {
new CK_ATTRIBUTE(CKA_VALUE, y),
new CK_ATTRIBUTE(CKA_PRIME, p),
new CK_ATTRIBUTE(CKA_BASE, g),
};
try {
} finally {
}
}
BigInteger g) throws PKCS11Exception {
new CK_ATTRIBUTE(CKA_VALUE, x),
new CK_ATTRIBUTE(CKA_PRIME, p),
new CK_ATTRIBUTE(CKA_BASE, g),
};
try {
return P11Key.privateKey
} finally {
}
}
throws PKCS11Exception, InvalidKeySpecException {
new CK_ATTRIBUTE(CKA_VALUE),
new CK_ATTRIBUTE(CKA_PRIME),
new CK_ATTRIBUTE(CKA_BASE),
};
);
return spec;
} else { // X.509 handled in superclass
throw new InvalidKeySpecException("Only DHPublicKeySpec and "
+ "X509EncodedKeySpec supported for DH public keys");
}
}
throws PKCS11Exception, InvalidKeySpecException {
new CK_ATTRIBUTE(CKA_VALUE),
new CK_ATTRIBUTE(CKA_PRIME),
new CK_ATTRIBUTE(CKA_BASE),
};
);
return spec;
} else { // PKCS#8 handled in superclass
throw new InvalidKeySpecException("Only DHPrivateKeySpec "
+ "and PKCS8EncodedKeySpec supported for DH private keys");
}
}
}
}