use of com.google.crypto.tink.proto.RsaSsaPkcs1PrivateKey in project tink by google.
the class RsaSsaPkcs1VerifyKeyManagerTest method createPrimitive.
@Test
public void createPrimitive() throws Exception {
if (TestUtil.isTsan()) {
// factory.createKey is too slow in Tsan.
return;
}
RsaSsaPkcs1KeyFormat keyFormat = RsaSsaPkcs1KeyFormat.newBuilder().setParams(RsaSsaPkcs1Params.newBuilder().setHashType(HashType.SHA256)).setModulusSizeInBits(3072).setPublicExponent(ByteString.copyFrom(RSAKeyGenParameterSpec.F4.toByteArray())).build();
RsaSsaPkcs1PrivateKey privateKey = factory.createKey(keyFormat);
RsaSsaPkcs1PublicKey publicKey = signManager.getPublicKey(privateKey);
PublicKeySign signer = signManager.getPrimitive(privateKey, PublicKeySign.class);
PublicKeyVerify verifier = verifyManager.getPrimitive(publicKey, PublicKeyVerify.class);
byte[] message = Random.randBytes(135);
verifier.verify(signer.sign(message), message);
}
use of com.google.crypto.tink.proto.RsaSsaPkcs1PrivateKey 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);
}
use of com.google.crypto.tink.proto.RsaSsaPkcs1PrivateKey in project tink by google.
the class RsaSsaPkcs1SignKeyManagerTest method createKey_smallKey.
@Test
public void createKey_smallKey() 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);
checkConsistency(key, format);
checkKey(key);
}
use of com.google.crypto.tink.proto.RsaSsaPkcs1PrivateKey in project tink by google.
the class RsaSsaPkcs1SignKeyManagerTest method createKey_largeKey.
@Test
public void createKey_largeKey() throws Exception {
if (TestUtil.isTsan()) {
// factory.createKey is too slow in Tsan.
return;
}
RsaSsaPkcs1KeyFormat format = createKeyFormat(HashType.SHA512, 4096, RSAKeyGenParameterSpec.F4);
RsaSsaPkcs1PrivateKey key = factory.createKey(format);
checkConsistency(key, format);
checkKey(key);
}
Aggregations