Search in sources :

Example 6 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method createCorruptedModulusPrimitive_throws.

@Test
public void createCorruptedModulusPrimitive_throws() throws Exception {
    RsaSsaPssKeyFormat format = createKeyFormat(HashType.SHA512, HashType.SHA512, 64, 4096, RSAKeyGenParameterSpec.F4);
    RsaSsaPssPrivateKey originalKey = factory.createKey(format);
    byte[] originalN = originalKey.getPublicKey().getN().toByteArray();
    originalN[0] = (byte) (originalN[0] ^ 0x01);
    ByteString corruptedN = ByteString.copyFrom(originalN);
    RsaSsaPssPublicKey corruptedPub = RsaSsaPssPublicKey.newBuilder().setVersion(originalKey.getPublicKey().getVersion()).setN(corruptedN).setE(originalKey.getPublicKey().getE()).build();
    RsaSsaPssPrivateKey corruptedKey = RsaSsaPssPrivateKey.newBuilder().setVersion(originalKey.getVersion()).setPublicKey(corruptedPub).setD(originalKey.getD()).setP(originalKey.getP()).setQ(originalKey.getQ()).setDp(originalKey.getDp()).setDq(originalKey.getDq()).setCrt(originalKey.getCrt()).build();
    assertThrows(GeneralSecurityException.class, () -> manager.getPrimitive(corruptedKey, PublicKeySign.class));
}
Also used : RsaSsaPssPublicKey(com.google.crypto.tink.proto.RsaSsaPssPublicKey) RsaSsaPssPrivateKey(com.google.crypto.tink.proto.RsaSsaPssPrivateKey) ByteString(com.google.protobuf.ByteString) RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) PublicKeySign(com.google.crypto.tink.PublicKeySign) Test(org.junit.Test)

Example 7 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method testRawRsa3072PssSha256F4TemplateWithManager.

@Test
public void testRawRsa3072PssSha256F4TemplateWithManager() throws Exception {
    RsaSsaPssKeyFormat format = RsaSsaPssKeyFormat.parseFrom(RsaSsaPssSignKeyManager.rawRsa3072PssSha256F4Template().getValue(), ExtensionRegistryLite.getEmptyRegistry());
    new RsaSsaPssSignKeyManager().keyFactory().validateKeyFormat(format);
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) Test(org.junit.Test)

Example 8 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method validateKeyFormat_valid.

@Test
public void validateKeyFormat_valid() throws Exception {
    RsaSsaPssKeyFormat format = validKeyFormat();
    factory.validateKeyFormat(format);
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) Test(org.junit.Test)

Example 9 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method validateKeyFormat_sha1Disallowed_throws.

@Test
public void validateKeyFormat_sha1Disallowed_throws() throws Exception {
    RsaSsaPssKeyFormat format = createKeyFormat(HashType.SHA1, HashType.SHA1, 32, 3072, RSAKeyGenParameterSpec.F4);
    assertThrows(GeneralSecurityException.class, () -> factory.validateKeyFormat(format));
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) Test(org.junit.Test)

Example 10 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method testRsa3072PssSha256F4TemplateWithManager.

@Test
public void testRsa3072PssSha256F4TemplateWithManager() throws Exception {
    RsaSsaPssKeyFormat format = RsaSsaPssKeyFormat.parseFrom(RsaSsaPssSignKeyManager.rsa3072PssSha256F4Template().getValue(), ExtensionRegistryLite.getEmptyRegistry());
    new RsaSsaPssSignKeyManager().keyFactory().validateKeyFormat(format);
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) Test(org.junit.Test)

Aggregations

RsaSsaPssKeyFormat (com.google.crypto.tink.proto.RsaSsaPssKeyFormat)29 Test (org.junit.Test)27 RsaSsaPssPrivateKey (com.google.crypto.tink.proto.RsaSsaPssPrivateKey)9 BigInteger (java.math.BigInteger)8 RsaSsaPssPublicKey (com.google.crypto.tink.proto.RsaSsaPssPublicKey)5 KeyTemplate (com.google.crypto.tink.KeyTemplate)4 PublicKeySign (com.google.crypto.tink.PublicKeySign)4 PublicKeyVerify (com.google.crypto.tink.PublicKeyVerify)3 RsaSsaPssParams (com.google.crypto.tink.proto.RsaSsaPssParams)3 ByteString (com.google.protobuf.ByteString)3 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)2 RSAPublicKey (java.security.interfaces.RSAPublicKey)2 RsaSsaPssVerifyJce (com.google.crypto.tink.subtle.RsaSsaPssVerifyJce)1 KeyFactory (java.security.KeyFactory)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)1 RSAKeyGenParameterSpec (java.security.spec.RSAKeyGenParameterSpec)1 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)1 HashMap (java.util.HashMap)1