Search in sources :

Example 66 with RSAPublicKeySpec

use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.

the class SignatureTest method testVerify_SHA1withRSA_Key_WrongExpectedSignature_Failure.

public void testVerify_SHA1withRSA_Key_WrongExpectedSignature_Failure() throws Exception {
    KeyFactory kf = KeyFactory.getInstance("RSA");
    RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
    PublicKey pubKey = kf.generatePublic(keySpec);
    Signature sig = Signature.getInstance("SHA1withRSA");
    sig.initVerify(pubKey);
    sig.update(Vector1Data);
    assertFalse("Signature should fail to verify", sig.verify(SHA1withRSA_Vector2Signature));
}
Also used : PublicKey(java.security.PublicKey) Signature(java.security.Signature) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) KeyFactory(java.security.KeyFactory)

Example 67 with RSAPublicKeySpec

use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.

the class SignatureTest method testVerify_NONEwithRSA_Key_WrongSignature_Failure.

public void testVerify_NONEwithRSA_Key_WrongSignature_Failure() throws Exception {
    KeyFactory kf = KeyFactory.getInstance("RSA");
    RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
    PublicKey pubKey = kf.generatePublic(pubKeySpec);
    Signature sig = Signature.getInstance("NONEwithRSA");
    sig.initVerify(pubKey);
    sig.update(Vector1Data);
    assertFalse("Invalid signature must not verify", sig.verify("Invalid".getBytes()));
}
Also used : PublicKey(java.security.PublicKey) Signature(java.security.Signature) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) KeyFactory(java.security.KeyFactory)

Example 68 with RSAPublicKeySpec

use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.

the class SignatureTest method testVerify_SHA384withRSA_Key_Success.

public void testVerify_SHA384withRSA_Key_Success() throws Exception {
    KeyFactory kf = KeyFactory.getInstance("RSA");
    RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
    PublicKey pubKey = kf.generatePublic(keySpec);
    Signature sig = Signature.getInstance("SHA384withRSA");
    sig.initVerify(pubKey);
    sig.update(Vector2Data);
    assertTrue("Signature must match expected signature", sig.verify(SHA384withRSA_Vector2Signature));
}
Also used : PublicKey(java.security.PublicKey) Signature(java.security.Signature) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) KeyFactory(java.security.KeyFactory)

Example 69 with RSAPublicKeySpec

use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.

the class SignatureTest method testVerify_NONEwithRSA_Key_SignatureTooSmall_Failure.

public void testVerify_NONEwithRSA_Key_SignatureTooSmall_Failure() throws Exception {
    KeyFactory kf = KeyFactory.getInstance("RSA");
    RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
    PublicKey pubKey = kf.generatePublic(pubKeySpec);
    Signature sig = Signature.getInstance("NONEwithRSA");
    sig.initVerify(pubKey);
    sig.update(Vector1Data);
    assertFalse("Invalid signature should not verify", sig.verify("Invalid sig".getBytes()));
}
Also used : PublicKey(java.security.PublicKey) Signature(java.security.Signature) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) KeyFactory(java.security.KeyFactory)

Example 70 with RSAPublicKeySpec

use of java.security.spec.RSAPublicKeySpec in project robovm by robovm.

the class SignatureTest method testVerify_SHA256withRSA_Key_Success.

public void testVerify_SHA256withRSA_Key_Success() throws Exception {
    KeyFactory kf = KeyFactory.getInstance("RSA");
    RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
    PublicKey pubKey = kf.generatePublic(keySpec);
    Signature sig = Signature.getInstance("SHA256withRSA");
    sig.initVerify(pubKey);
    sig.update(Vector2Data);
    assertTrue("Signature must match expected signature", sig.verify(SHA256withRSA_Vector2Signature));
}
Also used : PublicKey(java.security.PublicKey) Signature(java.security.Signature) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) KeyFactory(java.security.KeyFactory)

Aggregations

RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)85 KeyFactory (java.security.KeyFactory)61 PublicKey (java.security.PublicKey)48 RSAPublicKey (java.security.interfaces.RSAPublicKey)30 BigInteger (java.math.BigInteger)24 Signature (java.security.Signature)22 PrivateKey (java.security.PrivateKey)20 RSAPrivateKeySpec (java.security.spec.RSAPrivateKeySpec)17 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)14 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)12 Cipher (javax.crypto.Cipher)12 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)10 SecretKeyFactory (javax.crypto.SecretKeyFactory)10 IOException (java.io.IOException)9 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)9 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)8 KeySpec (java.security.spec.KeySpec)8 KeyPair (java.security.KeyPair)7 RSAPrivateCrtKeySpec (java.security.spec.RSAPrivateCrtKeySpec)6 InvalidKeyException (java.security.InvalidKeyException)5