use of java.security.spec.X509EncodedKeySpec in project lucene-solr by apache.
the class CryptoKeys method getX509PublicKey.
/**
* Create PublicKey from a .DER file
*/
public static PublicKey getX509PublicKey(byte[] buf) throws Exception {
X509EncodedKeySpec spec = new X509EncodedKeySpec(buf);
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePublic(spec);
}
use of java.security.spec.X509EncodedKeySpec in project karaf by apache.
the class KnownHostsManager method getKnownKeyInternal.
private PublicKey getKnownKeyInternal(SocketAddress remoteAddress, String checkAlgorithm, BufferedReader reader) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
String checkServerAddress = getAddressString(remoteAddress);
String line = reader.readLine();
while (line != null) {
String[] lineParts = line.split(" ");
String serverAddress = lineParts[0];
String algorithm = lineParts[1];
if (checkServerAddress.equals(serverAddress) && checkAlgorithm.equals(algorithm)) {
byte[] key = Base64.getDecoder().decode(lineParts[2].getBytes());
KeyFactory keyFactory = KeyFactory.getInstance(algorithm);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(key);
return keyFactory.generatePublic(keySpec);
}
line = reader.readLine();
}
return null;
}
use of java.security.spec.X509EncodedKeySpec in project cloudstack by apache.
the class SAMLUtils method savePublicKey.
public static String savePublicKey(PublicKey key) {
try {
KeyFactory keyFactory = SAMLUtils.getKeyFactory();
if (keyFactory == null)
return null;
X509EncodedKeySpec spec = keyFactory.getKeySpec(key, X509EncodedKeySpec.class);
return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), Charset.forName("UTF-8"));
} catch (InvalidKeySpecException e) {
s_logger.error("Unable to create KeyFactory:" + e.getMessage());
}
return null;
}
use of java.security.spec.X509EncodedKeySpec in project cloudstack by apache.
the class SAMLUtils method loadPublicKey.
public static PublicKey loadPublicKey(String publicKey) {
byte[] sigBytes = org.bouncycastle.util.encoders.Base64.decode(publicKey);
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(sigBytes);
KeyFactory keyFact = SAMLUtils.getKeyFactory();
if (keyFact == null)
return null;
try {
return keyFact.generatePublic(x509KeySpec);
} catch (InvalidKeySpecException e) {
s_logger.error("Unable to create PrivateKey from privateKey string:" + e.getMessage());
}
return null;
}
use of java.security.spec.X509EncodedKeySpec in project robovm by robovm.
the class X509CertificateTest method getRsaCertificatePublicKey.
private PublicKey getRsaCertificatePublicKey() throws Exception {
final InputStream ris = Support_Resources.getStream("x509/cert-rsa-pubkey.der");
try {
final int size = ris.available();
final DataInputStream is = new DataInputStream(ris);
final byte[] keyBytes = new byte[size];
is.readFully(keyBytes);
final KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePublic(new X509EncodedKeySpec(keyBytes));
} finally {
try {
ris.close();
} catch (IOException ignored) {
}
}
}
Aggregations