use of com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat in project tink by google.
the class RsaSsaPkcs1SignKeyManagerTest method testRawRsa4096SsaPkcs1Sha512F4TemplateWithManager.
@Test
public void testRawRsa4096SsaPkcs1Sha512F4TemplateWithManager() throws Exception {
RsaSsaPkcs1KeyFormat format = RsaSsaPkcs1KeyFormat.parseFrom(RsaSsaPkcs1SignKeyManager.rawRsa4096SsaPkcs1Sha512F4Template().getValue(), ExtensionRegistryLite.getEmptyRegistry());
new RsaSsaPkcs1SignKeyManager().keyFactory().validateKeyFormat(format);
}
use of com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat 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.RsaSsaPkcs1KeyFormat in project tink by google.
the class RsaSsaPkcs1SignKeyManagerTest method testRsa4096SsaPkcs1Sha512F4Template.
@Test
public void testRsa4096SsaPkcs1Sha512F4Template() throws Exception {
KeyTemplate template = RsaSsaPkcs1SignKeyManager.rsa4096SsaPkcs1Sha512F4Template();
assertThat(template.getTypeUrl()).isEqualTo(new RsaSsaPkcs1SignKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.TINK);
RsaSsaPkcs1KeyFormat format = RsaSsaPkcs1KeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.hasParams()).isTrue();
assertThat(format.getParams().getHashType()).isEqualTo(HashType.SHA512);
assertThat(format.getModulusSizeInBits()).isEqualTo(4096);
assertThat(new BigInteger(1, format.getPublicExponent().toByteArray())).isEqualTo(BigInteger.valueOf(65537));
}
use of com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat in project tink by google.
the class RsaSsaPkcs1SignKeyManagerTest method validateKeyFormat_valid.
@Test
public void validateKeyFormat_valid() throws Exception {
RsaSsaPkcs1KeyFormat format = validKeyFormat();
factory.validateKeyFormat(format);
}
use of com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat 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);
}
Aggregations