use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.
the class CipherTest method getDecryptKey.
private static synchronized Key getDecryptKey(String algorithm) throws Exception {
Key key = DECRYPT_KEYS.get(algorithm);
if (key != null) {
return key;
}
if (algorithm.startsWith("RSA")) {
KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
key = kf.generatePublic(keySpec);
} else {
assertFalse(algorithm, isAsymmetric(algorithm));
key = getEncryptKey(algorithm);
}
DECRYPT_KEYS.put(algorithm, key);
return key;
}
use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.
the class CipherTest method testRSA_ECB_NoPadding_GetBlockSize_Success.
private void testRSA_ECB_NoPadding_GetBlockSize_Success(String provider) throws Exception {
Cipher c = Cipher.getInstance("RSA/ECB/NoPadding", provider);
if (StandardNames.IS_RI) {
assertEquals(0, c.getBlockSize());
} else {
try {
c.getBlockSize();
fail();
} catch (IllegalStateException expected) {
}
}
KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
final PublicKey pubKey = kf.generatePublic(pubKeySpec);
c.init(Cipher.ENCRYPT_MODE, pubKey);
assertEquals(getExpectedBlockSize("RSA", Cipher.ENCRYPT_MODE, provider), c.getBlockSize());
}
use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.
the class RSAKeyTest method test_getModulus.
/**
* java.security.interfaces.RSAKey
* #getModulus()
* test covers following use cases
* Case 1: check private key
* Case 2: check public key
*/
public void test_getModulus() throws Exception {
KeyFactory gen = KeyFactory.getInstance("RSA");
final BigInteger n = BigInteger.valueOf(3233);
final BigInteger d = BigInteger.valueOf(2753);
final BigInteger e = BigInteger.valueOf(17);
RSAKey key = null;
// Case 1: check private key
key = (RSAKey) gen.generatePrivate(new RSAPrivateKeySpec(n, d));
assertEquals("invalid modulus", n, key.getModulus());
// Case 2: check public key
key = (RSAKey) gen.generatePublic(new RSAPublicKeySpec(n, e));
assertEquals("invalid modulus", n, key.getModulus());
}
use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.
the class RSAPublicKeyTest method test_getPublicExponent.
/**
* java.security.interfaces.RSAPublicKey
* #getPublicExponent()
*/
public void test_getPublicExponent() throws Exception {
KeyFactory gen = KeyFactory.getInstance("RSA");
final BigInteger n = BigInteger.valueOf(3233);
final BigInteger e = BigInteger.valueOf(17);
RSAPublicKey key = (RSAPublicKey) gen.generatePublic(new RSAPublicKeySpec(n, e));
assertEquals("invalid public exponent", e, key.getPublicExponent());
}
use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.
the class ServerKeyExchange method getRSAPublicKey.
/**
* Returns RSAPublicKey generated using ServerRSAParams
* (rsa_modulus and rsa_exponent).
*
* @return
*/
public RSAPublicKey getRSAPublicKey() {
if (key != null) {
return key;
}
try {
KeyFactory kf = KeyFactory.getInstance("RSA");
key = (RSAPublicKey) kf.generatePublic(new RSAPublicKeySpec(par1, par2));
} catch (Exception e) {
return null;
}
return key;
}
Aggregations