use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.
the class CipherTest method testRSA_ECB_NoPadding_Public_OnlyDoFinal_Success.
private void testRSA_ECB_NoPadding_Public_OnlyDoFinal_Success(String provider) throws Exception {
KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
final PublicKey privKey = kf.generatePublic(keySpec);
Cipher c = Cipher.getInstance("RSA/ECB/NoPadding", provider);
/*
* You're actually encrypting with public keys, but there is no
* distinction made here. It's all keyed off of what kind of key you're
* using. ENCRYPT_MODE and DECRYPT_MODE are the same.
*/
c.init(Cipher.ENCRYPT_MODE, privKey);
byte[] encrypted = c.doFinal(RSA_Vector1_Encrypt_Private);
assertEncryptedEqualsNoPadding(provider, Cipher.ENCRYPT_MODE, RSA_2048_Vector1, encrypted);
c.init(Cipher.DECRYPT_MODE, privKey);
encrypted = c.doFinal(RSA_Vector1_Encrypt_Private);
assertEncryptedEqualsNoPadding(provider, Cipher.DECRYPT_MODE, RSA_2048_Vector1, encrypted);
}
use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.
the class CipherTest method testRSA_ECB_NoPadding_GetIV_Success.
private void testRSA_ECB_NoPadding_GetIV_Success(String provider) throws Exception {
KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
final PublicKey pubKey = kf.generatePublic(pubKeySpec);
Cipher c = Cipher.getInstance("RSA/ECB/NoPadding", provider);
assertNull("ECB mode has no IV and should be null", c.getIV());
c.init(Cipher.ENCRYPT_MODE, pubKey);
assertNull("ECB mode has no IV and should be null", c.getIV());
}
use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.
the class RSAPublicKeySpecTest method testGetModulus.
/**
* Test for <code>getModulus()</code> method<br>
* Assertion: returns modulus
*/
public final void testGetModulus() {
RSAPublicKeySpec rpks = new RSAPublicKeySpec(BigInteger.valueOf(1234567890L), BigInteger.valueOf(3L));
assertTrue(BigInteger.valueOf(1234567890L).equals(rpks.getModulus()));
}
use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.
the class RSAPublicKeySpecTest method testRSAPublicKeySpec01.
/**
* Test #1 for <code>RSAPublicKeySpec</code> constructor
* Assertion: Constructs <code>RSAPublicKeySpec</code>
* object using valid parameters
*/
public final void testRSAPublicKeySpec01() {
KeySpec ks = new RSAPublicKeySpec(BigInteger.valueOf(1234567890L), BigInteger.valueOf(3L));
assertTrue(ks instanceof RSAPublicKeySpec);
}
use of java.security.spec.RSAPublicKeySpec in project XobotOS by xamarin.
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