use of java.security.spec.EncodedKeySpec in project j2objc by google.
the class EncodedKeySpecTest method testGetEncoded.
/**
* Tests that <code>getEncoded()</code> method returns valid byte array
*/
public final void testGetEncoded() {
byte[] encodedKey = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 };
EncodedKeySpec meks = new MyEncodedKeySpec(encodedKey);
/* Get encoded key */
byte[] ek = meks.getEncoded();
/* Check returned array */
boolean result = true;
for (int i = 0; i < encodedKey.length; i++) {
if (encodedKey[i] != ek[i]) {
/* indicate failure */
result = false;
}
}
/* passed */
assertTrue(result);
}
use of java.security.spec.EncodedKeySpec in project j2objc by google.
the class PKCS8EncodedKeySpecTest method testPKCS8EncodedKeySpec.
//
// Tests
//
/**
* Test for <code>PKCS8EncodedKeySpec</code> constructor<br>
* Assertion: constructs new <code>PKCS8EncodedKeySpec</code>
* object using valid parameter
*/
public final void testPKCS8EncodedKeySpec() {
byte[] encodedKey = new byte[] { (byte) 1, (byte) 2, (byte) 3, (byte) 4 };
EncodedKeySpec eks = new PKCS8EncodedKeySpec(encodedKey);
assertTrue(eks instanceof PKCS8EncodedKeySpec);
try {
eks = new PKCS8EncodedKeySpec(null);
fail("expected NullPointerException");
} catch (NullPointerException e) {
// ok
}
}
use of java.security.spec.EncodedKeySpec in project j2objc by google.
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.EncodedKeySpec in project gocd by gocd.
the class EncryptionHelper method getRSAPublicKeyFrom.
private static PublicKey getRSAPublicKeyFrom(String content) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
PemReader reader = new PemReader(new StringReader(content));
EncodedKeySpec spec = new X509EncodedKeySpec(reader.readPemObject().getContent());
return KeyFactory.getInstance("RSA").generatePublic(spec);
}
Aggregations