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) {
}
}
}
use of java.security.spec.X509EncodedKeySpec in project robovm by robovm.
the class SignatureTest method test18566.
// http://code.google.com/p/android/issues/detail?id=18566
// http://b/5038554
public void test18566() throws Exception {
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(PK_BYTES);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey pk = keyFactory.generatePublic(keySpec);
Signature sig = Signature.getInstance("SHA256withRSA");
sig.initVerify(pk);
sig.update(CONTENT);
assertTrue(sig.verify(SIGNATURE));
}
use of java.security.spec.X509EncodedKeySpec in project robovm by robovm.
the class X509EncodedKeySpecTest method testX509EncodedKeySpec.
//
// Test cases
//
/**
* Test for <code>X509EncodedKeySpec</code> constructor<br>
* Assertion: constructs new <code>X509EncodedKeySpec</code>
* object using valid parameter
*/
public final void testX509EncodedKeySpec() {
byte[] encodedKey = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 };
EncodedKeySpec eks = new X509EncodedKeySpec(encodedKey);
assertTrue(eks instanceof X509EncodedKeySpec);
try {
eks = new X509EncodedKeySpec(null);
fail("expected NullPointerException");
} catch (NullPointerException e) {
// ok
}
}
use of java.security.spec.X509EncodedKeySpec in project robovm by robovm.
the class X509EncodedKeySpecTest method testGetFormat.
/**
* Test for <code>getFormat()</code> method
* Assertion: returns format name (always "X.509")
*/
public final void testGetFormat() {
byte[] encodedKey = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 };
X509EncodedKeySpec meks = new X509EncodedKeySpec(encodedKey);
assertEquals("X.509", meks.getFormat());
}
Aggregations