use of java.security.spec.EncodedKeySpec in project spring-security-oauth by spring-projects.
the class RSAKeySecret method createPublicKey.
/**
* Creates a public key from the X509-encoded value of the given bytes.
*
* @param publicKey The X509-encoded public key bytes.
* @return The public key.
*/
public static PublicKey createPublicKey(byte[] publicKey) {
if (publicKey == null) {
return null;
}
try {
KeyFactory fac = KeyFactory.getInstance("RSA");
EncodedKeySpec spec = new X509EncodedKeySpec(publicKey);
return fac.generatePublic(spec);
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
} catch (InvalidKeySpecException e) {
throw new IllegalStateException(e);
}
}
use of java.security.spec.EncodedKeySpec in project spring-security-oauth by spring-projects.
the class RSAKeySecret method createPrivateKey.
/**
* Creates a private key from the PKCS#8-encoded value of the given bytes.
*
* @param privateKey The PKCS#8-encoded private key bytes.
* @return The private key.
*/
public static PrivateKey createPrivateKey(byte[] privateKey) {
if (privateKey == null) {
return null;
}
try {
KeyFactory fac = KeyFactory.getInstance("RSA");
EncodedKeySpec spec = new PKCS8EncodedKeySpec(privateKey);
return fac.generatePrivate(spec);
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
} catch (InvalidKeySpecException e) {
throw new IllegalStateException(e);
}
}
use of java.security.spec.EncodedKeySpec in project data-transfer-project by google.
the class PublicPrivateKeyPairGenerator method parsePublicKey.
/**
* Parses the given {@code encoded} public key.
*/
public static PublicKey parsePublicKey(String encoded) {
byte[] decoded = BaseEncoding.base64Url().decode(encoded);
EncodedKeySpec spec = new X509EncodedKeySpec(decoded);
KeyFactory keyFactory;
try {
keyFactory = KeyFactory.getInstance(ALGORITHM);
} catch (NoSuchAlgorithmException e) {
logger.error("NoSuchAlgorithmException for: {}", ALGORITHM, e);
throw new RuntimeException("NoSuchAlgorithmException generating public keyFactory", e);
}
try {
return keyFactory.generatePublic(spec);
} catch (InvalidKeySpecException e) {
logger.error("InvalidKeySpecException for: {}", spec.getEncoded().length, e);
throw new RuntimeException("InvalidKeySpecException generating public key", e);
}
}
use of java.security.spec.EncodedKeySpec in project spring-security by spring-projects.
the class NimbusJwtDecoderTests method key.
private RSAPublicKey key() throws InvalidKeySpecException {
byte[] decoded = Base64.getDecoder().decode(VERIFY_KEY.getBytes());
EncodedKeySpec spec = new X509EncodedKeySpec(decoded);
return (RSAPublicKey) kf.generatePublic(spec);
}
use of java.security.spec.EncodedKeySpec in project spring-security by spring-projects.
the class NimbusReactiveJwtDecoderTests method key.
private RSAPublicKey key() throws InvalidKeySpecException {
byte[] decoded = Base64.getDecoder().decode(this.publicKey.getBytes());
EncodedKeySpec spec = new X509EncodedKeySpec(decoded);
return (RSAPublicKey) kf.generatePublic(spec);
}
Aggregations