Search in sources :

Example 6 with Ed25519PublicKey

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

the class Ed25519PublicKeyManagerTest method validateKey_wrongLength64_throws.

@Test
public void validateKey_wrongLength64_throws() throws Exception {
    Ed25519PublicKey publicKey = signManager.getPublicKey(createPrivateKey());
    Ed25519PublicKey invalidKey = Ed25519PublicKey.newBuilder(publicKey).setKeyValue(ByteString.copyFrom(Random.randBytes(64))).build();
    assertThrows(GeneralSecurityException.class, () -> verifyManager.validateKey(invalidKey));
}
Also used : Ed25519PublicKey(com.google.crypto.tink.proto.Ed25519PublicKey) Test(org.junit.Test)

Example 7 with Ed25519PublicKey

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

the class Ed25519PublicKeyManagerTest method validateKey.

@Test
public void validateKey() throws Exception {
    Ed25519PublicKey publicKey = signManager.getPublicKey(createPrivateKey());
    verifyManager.validateKey(publicKey);
}
Also used : Ed25519PublicKey(com.google.crypto.tink.proto.Ed25519PublicKey) Test(org.junit.Test)

Example 8 with Ed25519PublicKey

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

the class Ed25519PublicKeyManagerTest method validateKey_wrongVersion.

@Test
public void validateKey_wrongVersion() throws Exception {
    Ed25519PublicKey publicKey = signManager.getPublicKey(createPrivateKey());
    Ed25519PublicKey invalidKey = Ed25519PublicKey.newBuilder(publicKey).setVersion(1).build();
    assertThrows(GeneralSecurityException.class, () -> verifyManager.validateKey(invalidKey));
}
Also used : Ed25519PublicKey(com.google.crypto.tink.proto.Ed25519PublicKey) Test(org.junit.Test)

Example 9 with Ed25519PublicKey

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

the class Ed25519PublicKeyManagerTest method createPrimitive.

@Test
public void createPrimitive() throws Exception {
    Ed25519PrivateKey privateKey = createPrivateKey();
    Ed25519PublicKey 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);
}
Also used : Ed25519PrivateKey(com.google.crypto.tink.proto.Ed25519PrivateKey) Ed25519PublicKey(com.google.crypto.tink.proto.Ed25519PublicKey) PublicKeyVerify(com.google.crypto.tink.PublicKeyVerify) PublicKeySign(com.google.crypto.tink.PublicKeySign) Test(org.junit.Test)

Example 10 with Ed25519PublicKey

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

the class Ed25519PublicKeyManagerTest method createPrimitive_anotherKey_throws.

@Test
public void createPrimitive_anotherKey_throws() throws Exception {
    Ed25519PrivateKey privateKey = createPrivateKey();
    // Create a different key.
    Ed25519PublicKey publicKey = signManager.getPublicKey(createPrivateKey());
    PublicKeySign signer = signManager.getPrimitive(privateKey, PublicKeySign.class);
    PublicKeyVerify verifier = verifyManager.getPrimitive(publicKey, PublicKeyVerify.class);
    byte[] message = Random.randBytes(135);
    byte[] signature = signer.sign(message);
    assertThrows(GeneralSecurityException.class, () -> verifier.verify(signature, message));
}
Also used : Ed25519PrivateKey(com.google.crypto.tink.proto.Ed25519PrivateKey) Ed25519PublicKey(com.google.crypto.tink.proto.Ed25519PublicKey) PublicKeyVerify(com.google.crypto.tink.PublicKeyVerify) PublicKeySign(com.google.crypto.tink.PublicKeySign) Test(org.junit.Test)

Aggregations

Ed25519PublicKey (com.google.crypto.tink.proto.Ed25519PublicKey)12 Test (org.junit.Test)9 Ed25519PrivateKey (com.google.crypto.tink.proto.Ed25519PrivateKey)5 PublicKeySign (com.google.crypto.tink.PublicKeySign)2 PublicKeyVerify (com.google.crypto.tink.PublicKeyVerify)2 KeyData (com.google.crypto.tink.proto.KeyData)2 Ed25519Sign (com.google.crypto.tink.subtle.Ed25519Sign)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Ed25519KeyFormat (com.google.crypto.tink.proto.Ed25519KeyFormat)1 Ed25519Verify (com.google.crypto.tink.subtle.Ed25519Verify)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1