Search in sources :

Example 6 with JwtRsaSsaPkcs1KeyFormat

use of com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat in project tink by google.

the class JwtRsaSsaPkcs1SignKeyManagerTest method testJwtRsa4096AlgoRS512F4TemplateWithManager_ok.

@Test
public void testJwtRsa4096AlgoRS512F4TemplateWithManager_ok() throws Exception {
    JwtRsaSsaPkcs1KeyFormat format = JwtRsaSsaPkcs1KeyFormat.parseFrom(KeyTemplates.get("JWT_RS512_4096_F4").getValue(), ExtensionRegistryLite.getEmptyRegistry());
    new JwtRsaSsaPkcs1SignKeyManager().keyFactory().validateKeyFormat(format);
}
Also used : JwtRsaSsaPkcs1KeyFormat(com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat) Test(org.junit.Test)

Example 7 with JwtRsaSsaPkcs1KeyFormat

use of com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat in project tink by google.

the class JwtRsaSsaPkcs1SignKeyManagerTest method testJwtRsa3072AlgoRS384F4TemplateWithManager_ok.

@Test
public void testJwtRsa3072AlgoRS384F4TemplateWithManager_ok() throws Exception {
    JwtRsaSsaPkcs1KeyFormat format = JwtRsaSsaPkcs1KeyFormat.parseFrom(KeyTemplates.get("JWT_RS384_3072_F4").getValue(), ExtensionRegistryLite.getEmptyRegistry());
    new JwtRsaSsaPkcs1SignKeyManager().keyFactory().validateKeyFormat(format);
}
Also used : JwtRsaSsaPkcs1KeyFormat(com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat) Test(org.junit.Test)

Example 8 with JwtRsaSsaPkcs1KeyFormat

use of com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat in project tink by google.

the class JwtRsaSsaPkcs1SignKeyManagerTest method invalidKeyFormat_smallPublicExponents_throw.

// Note: we use Theory as a parametrized test -- different from what the Theory framework intends.
@Theory
public void invalidKeyFormat_smallPublicExponents_throw(@FromDataPoints("algorithmParam") JwtRsaSsaPkcs1Algorithm algorithm, @FromDataPoints("sizes") int keySize) throws GeneralSecurityException {
    JwtRsaSsaPkcs1KeyFormat format = createKeyFormat(algorithm, keySize, RSAKeyGenParameterSpec.F4.subtract(BigInteger.ONE));
    assertThrows(GeneralSecurityException.class, () -> factory.validateKeyFormat(format));
}
Also used : JwtRsaSsaPkcs1KeyFormat(com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat) Theory(org.junit.experimental.theories.Theory)

Example 9 with JwtRsaSsaPkcs1KeyFormat

use of com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat in project tink by google.

the class JwtRsaSsaPkcs1SignKeyManagerTest method testJwtRsa3072AlgoRS256F4TemplateWithManager_ok.

@Test
public void testJwtRsa3072AlgoRS256F4TemplateWithManager_ok() throws Exception {
    JwtRsaSsaPkcs1KeyFormat format = JwtRsaSsaPkcs1KeyFormat.parseFrom(KeyTemplates.get("JWT_RS256_3072_F4").getValue(), ExtensionRegistryLite.getEmptyRegistry());
    new JwtRsaSsaPkcs1SignKeyManager().keyFactory().validateKeyFormat(format);
}
Also used : JwtRsaSsaPkcs1KeyFormat(com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat) Test(org.junit.Test)

Example 10 with JwtRsaSsaPkcs1KeyFormat

use of com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat in project tink by google.

the class JwtRsaSsaPkcs1SignKeyManagerTest method checkTemplate.

private static void checkTemplate(KeyTemplate template, JwtRsaSsaPkcs1Algorithm algorithm, int moduloSize, int publicExponent) throws Exception {
    assertThat(template.getTypeUrl()).isEqualTo(new JwtRsaSsaPkcs1SignKeyManager().getKeyType());
    JwtRsaSsaPkcs1KeyFormat format = JwtRsaSsaPkcs1KeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.getAlgorithm()).isEqualTo(algorithm);
    assertThat(format.getModulusSizeInBits()).isEqualTo(moduloSize);
    assertThat(new BigInteger(1, format.getPublicExponent().toByteArray())).isEqualTo(BigInteger.valueOf(publicExponent));
}
Also used : JwtRsaSsaPkcs1KeyFormat(com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat) BigInteger(java.math.BigInteger)

Aggregations

JwtRsaSsaPkcs1KeyFormat (com.google.crypto.tink.proto.JwtRsaSsaPkcs1KeyFormat)12 Theory (org.junit.experimental.theories.Theory)6 JwtRsaSsaPkcs1PrivateKey (com.google.crypto.tink.proto.JwtRsaSsaPkcs1PrivateKey)4 Test (org.junit.Test)4 JwtRsaSsaPkcs1PublicKey (com.google.crypto.tink.proto.JwtRsaSsaPkcs1PublicKey)3 ByteString (com.google.protobuf.ByteString)3 BigInteger (java.math.BigInteger)2 JwtRsaSsaPkcs1Algorithm (com.google.crypto.tink.proto.JwtRsaSsaPkcs1Algorithm)1 InputStream (java.io.InputStream)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 RSAKeyGenParameterSpec (java.security.spec.RSAKeyGenParameterSpec)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1