Search in sources :

Example 1 with RsaSsaPssVerifyJce

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

the class RsaSsaPssSignKeyManagerTest method createPrimitive.

@Test
public void createPrimitive() throws Exception {
    if (TestUtil.isTsan()) {
        // factory.createKey is too slow in Tsan.
        return;
    }
    RsaSsaPssKeyFormat format = createKeyFormat(HashType.SHA512, HashType.SHA512, 64, 4096, RSAKeyGenParameterSpec.F4);
    RsaSsaPssPrivateKey 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));
    RsaSsaPssParams params = key.getPublicKey().getParams();
    PublicKeyVerify verifier = new RsaSsaPssVerifyJce(publicKey, SigUtil.toHashType(params.getSigHash()), SigUtil.toHashType(params.getMgf1Hash()), params.getSaltLength());
    byte[] message = Random.randBytes(135);
    verifier.verify(signer.sign(message), message);
}
Also used : RsaSsaPssPrivateKey(com.google.crypto.tink.proto.RsaSsaPssPrivateKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) RsaSsaPssVerifyJce(com.google.crypto.tink.subtle.RsaSsaPssVerifyJce) PublicKeyVerify(com.google.crypto.tink.PublicKeyVerify) BigInteger(java.math.BigInteger) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) RsaSsaPssParams(com.google.crypto.tink.proto.RsaSsaPssParams) PublicKeySign(com.google.crypto.tink.PublicKeySign) KeyFactory(java.security.KeyFactory) Test(org.junit.Test)

Aggregations

PublicKeySign (com.google.crypto.tink.PublicKeySign)1 PublicKeyVerify (com.google.crypto.tink.PublicKeyVerify)1 RsaSsaPssKeyFormat (com.google.crypto.tink.proto.RsaSsaPssKeyFormat)1 RsaSsaPssParams (com.google.crypto.tink.proto.RsaSsaPssParams)1 RsaSsaPssPrivateKey (com.google.crypto.tink.proto.RsaSsaPssPrivateKey)1 RsaSsaPssVerifyJce (com.google.crypto.tink.subtle.RsaSsaPssVerifyJce)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