use of java.security.KeyFactory in project bigbluebutton by bigbluebutton.
the class RSA_SHA1 method getPrivateKeyFromDer.
private PrivateKey getPrivateKeyFromDer(byte[] privateKeyObject) throws GeneralSecurityException {
KeyFactory fac = KeyFactory.getInstance("RSA");
EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(privateKeyObject);
return fac.generatePrivate(privKeySpec);
}
use of java.security.KeyFactory in project bigbluebutton by bigbluebutton.
the class RSA_SHA1 method getPublicKeyFromDer.
private PublicKey getPublicKeyFromDer(byte[] publicKeyObject) throws GeneralSecurityException {
KeyFactory fac = KeyFactory.getInstance("RSA");
EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(publicKeyObject);
return fac.generatePublic(pubKeySpec);
}
use of java.security.KeyFactory in project gocd by gocd.
the class RegistrationJSONizer method fromJson.
public static Registration fromJson(String json) {
Map map = GSON.fromJson(json, Map.class);
if (map.isEmpty()) {
return Registration.createNullPrivateKeyEntry();
}
List<Certificate> chain = new ArrayList<>();
try {
PemReader reader = new PemReader(new StringReader((String) map.get("agentPrivateKey")));
KeyFactory kf = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(reader.readPemObject().getContent());
PrivateKey privateKey = kf.generatePrivate(spec);
String agentCertificate = (String) map.get("agentCertificate");
PemReader certReader = new PemReader(new StringReader(agentCertificate));
while (true) {
PemObject obj = certReader.readPemObject();
if (obj == null) {
break;
}
chain.add(CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(obj.getContent())));
}
return new Registration(privateKey, chain.toArray(new Certificate[chain.size()]));
} catch (IOException | NoSuchAlgorithmException | CertificateException | InvalidKeySpecException e) {
throw bomb(e);
}
}
use of java.security.KeyFactory in project cardslib by gabrielemariotti.
the class Security method generatePublicKey.
/**
* Generates a PublicKey instance from a string containing the
* Base64-encoded public key.
*
* @param encodedPublicKey Base64-encoded public key
* @throws IllegalArgumentException if encodedPublicKey is invalid
*/
public static PublicKey generatePublicKey(String encodedPublicKey) {
try {
byte[] decodedKey = Base64.decode(encodedPublicKey);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_FACTORY_ALGORITHM);
return keyFactory.generatePublic(new X509EncodedKeySpec(decodedKey));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (InvalidKeySpecException e) {
Log.e(TAG, "Invalid key specification.");
throw new IllegalArgumentException(e);
} catch (Base64DecoderException e) {
Log.e(TAG, "Base64 decoding failed.");
throw new IllegalArgumentException(e);
}
}
use of java.security.KeyFactory in project j2objc by google.
the class RSAPrivateKeyTest method test_getPrivateExponent.
/**
* java.security.interfaces.RSAPrivateKey
* #getPrivateExponent()
*/
public void test_getPrivateExponent() throws Exception {
KeyFactory gen = KeyFactory.getInstance("RSA");
final BigInteger n = BigInteger.valueOf(3233);
final BigInteger d = BigInteger.valueOf(2753);
RSAPrivateKey key = (RSAPrivateKey) gen.generatePrivate(new RSAPrivateKeySpec(n, d));
assertEquals("invalid private exponent", d, key.getPrivateExponent());
}
Aggregations