Lines Matching refs:key

100      * or RSAPrivate(Crt)KeyImpl. If the key is not an RSA key or cannot be
105 public static RSAKey toRSAKey(Key key) throws InvalidKeyException {
106 if ((key instanceof RSAPrivateKeyImpl) ||
107 (key instanceof RSAPrivateCrtKeyImpl) ||
108 (key instanceof RSAPublicKeyImpl)) {
109 return (RSAKey)key;
111 return (RSAKey)INSTANCE.engineTranslateKey(key);
130 * Check the length of an RSA key modulus/exponent to make sure it
132 * max key sizes that may or may not match with a system defined value.
176 * Translate an RSA key into a SunRsaSign RSA key. If conversion is
180 protected Key engineTranslateKey(Key key) throws InvalidKeyException {
181 if (key == null) {
184 String keyAlg = key.getAlgorithm();
186 throw new InvalidKeyException("Not an RSA key: " + keyAlg);
188 if (key instanceof PublicKey) {
189 return translatePublicKey((PublicKey)key);
190 } else if (key instanceof PrivateKey) {
191 return translatePrivateKey((PrivateKey)key);
193 throw new InvalidKeyException("Neither a public nor a private key");
222 private PublicKey translatePublicKey(PublicKey key)
224 if (key instanceof RSAPublicKey) {
225 if (key instanceof RSAPublicKeyImpl) {
226 return key;
228 RSAPublicKey rsaKey = (RSAPublicKey)key;
236 throw new InvalidKeyException("Invalid key", e);
238 } else if ("X.509".equals(key.getFormat())) {
239 byte[] encoded = key.getEncoded();
248 private PrivateKey translatePrivateKey(PrivateKey key)
250 if (key instanceof RSAPrivateCrtKey) {
251 if (key instanceof RSAPrivateCrtKeyImpl) {
252 return key;
254 RSAPrivateCrtKey rsaKey = (RSAPrivateCrtKey)key;
268 throw new InvalidKeyException("Invalid key", e);
270 } else if (key instanceof RSAPrivateKey) {
271 if (key instanceof RSAPrivateKeyImpl) {
272 return key;
274 RSAPrivateKey rsaKey = (RSAPrivateKey)key;
282 throw new InvalidKeyException("Invalid key", e);
284 } else if ("PKCS#8".equals(key.getFormat())) {
285 byte[] encoded = key.getEncoded();
341 protected <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec)
344 // convert key to one of our keys
345 // this also verifies that the key is a valid RSA key and ensures
347 key = engineTranslateKey(key);
351 if (key instanceof RSAPublicKey) {
352 RSAPublicKey rsaKey = (RSAPublicKey)key;
359 return (T) new X509EncodedKeySpec(key.getEncoded());
365 } else if (key instanceof RSAPrivateKey) {
367 return (T) new PKCS8EncodedKeySpec(key.getEncoded());
369 if (key instanceof RSAPrivateCrtKey) {
370 RSAPrivateCrtKey crtKey = (RSAPrivateCrtKey)key;
386 RSAPrivateKey rsaKey = (RSAPrivateKey)key;
398 throw new InvalidKeySpecException("Neither public nor private key");