Search in sources :

Example 1 with RsaSsaPkcs1VerifyJce

use of com.google.crypto.tink.subtle.RsaSsaPkcs1VerifyJce in project tink by google.

the class RsaSsaPkcs1SignKeyManagerTest method createPrimitive.

@Test
public void createPrimitive() throws Exception {
    if (TestUtil.isTsan()) {
        // factory.createKey is too slow in Tsan.
        return;
    }
    RsaSsaPkcs1KeyFormat format = createKeyFormat(HashType.SHA256, 3072, RSAKeyGenParameterSpec.F4);
    RsaSsaPkcs1PrivateKey key = factory.createKey(format);
    PublicKeySign signer = manager.getPrimitive(key, PublicKeySign.class);
    KeyFactory kf = EngineFactory.KEY_FACTORY.getInstance("RSA");
    BigInteger modulus = new BigInteger(1, key.getPublicKey().getN().toByteArray());
    BigInteger exponent = new BigInteger(1, key.getPublicKey().getE().toByteArray());
    RSAPublicKey publicKey = (RSAPublicKey) kf.generatePublic(new RSAPublicKeySpec(modulus, exponent));
    PublicKeyVerify verifier = new RsaSsaPkcs1VerifyJce(publicKey, SigUtil.toHashType(key.getPublicKey().getParams().getHashType()));
    byte[] message = Random.randBytes(135);
    verifier.verify(signer.sign(message), message);
}
Also used : RsaSsaPkcs1PrivateKey(com.google.crypto.tink.proto.RsaSsaPkcs1PrivateKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) PublicKeyVerify(com.google.crypto.tink.PublicKeyVerify) BigInteger(java.math.BigInteger) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) PublicKeySign(com.google.crypto.tink.PublicKeySign) KeyFactory(java.security.KeyFactory) RsaSsaPkcs1KeyFormat(com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat) RsaSsaPkcs1VerifyJce(com.google.crypto.tink.subtle.RsaSsaPkcs1VerifyJce) Test(org.junit.Test)

Aggregations

PublicKeySign (com.google.crypto.tink.PublicKeySign)1 PublicKeyVerify (com.google.crypto.tink.PublicKeyVerify)1 RsaSsaPkcs1KeyFormat (com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat)1 RsaSsaPkcs1PrivateKey (com.google.crypto.tink.proto.RsaSsaPkcs1PrivateKey)1 RsaSsaPkcs1VerifyJce (com.google.crypto.tink.subtle.RsaSsaPkcs1VerifyJce)1 BigInteger (java.math.BigInteger)1 KeyFactory (java.security.KeyFactory)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)1 Test (org.junit.Test)1