use of com.google.crypto.tink.subtle.Ed25519Verify in project tink by google.
the class Ed25519PrivateKeyManagerTest method createPrimitive.
@Test
public void createPrimitive() throws Exception {
Ed25519PrivateKey privateKey = factory.createKey(Ed25519KeyFormat.getDefaultInstance());
PublicKeySign signer = manager.getPrimitive(privateKey, PublicKeySign.class);
PublicKeyVerify verifier = new Ed25519Verify(privateKey.getPublicKey().getKeyValue().toByteArray());
byte[] message = Random.randBytes(135);
verifier.verify(signer.sign(message), message);
}
use of com.google.crypto.tink.subtle.Ed25519Verify in project tink by google.
the class Ed25519PublicKeyManager method getPrimitive.
@Override
public PublicKeyVerify getPrimitive(MessageLite key) throws GeneralSecurityException {
if (!(key instanceof Ed25519PublicKey)) {
throw new GeneralSecurityException("expected Ed25519PublicKey proto");
}
Ed25519PublicKey keyProto = (Ed25519PublicKey) key;
validate(keyProto);
return new Ed25519Verify(keyProto.getKeyValue().toByteArray());
}
use of com.google.crypto.tink.subtle.Ed25519Verify in project tink by google.
the class Ed25519PrivateKeyManagerTest method testBasic.
@Test
public void testBasic() throws Exception {
Ed25519PrivateKeyManager manager = new Ed25519PrivateKeyManager();
KeyTemplate template = SignatureKeyTemplates.ED25519;
MessageLite key = manager.newKey(template);
assertTrue(key instanceof Ed25519PrivateKey);
Ed25519PrivateKey keyProto = (Ed25519PrivateKey) key;
assertEquals(32, keyProto.getKeyValue().size());
PublicKeySign signer = manager.getPrimitive(key);
assertTrue(signer instanceof Ed25519Sign);
byte[] message = Random.randBytes(20);
byte[] signature = signer.sign(message);
assertEquals(64, signature.length);
Ed25519PublicKeyManager publicKeyManager = new Ed25519PublicKeyManager();
PublicKeyVerify verifier = publicKeyManager.getPrimitive(keyProto.getPublicKey());
assertTrue(verifier instanceof Ed25519Verify);
try {
verifier.verify(signature, message);
} catch (GeneralSecurityException e) {
fail("Do not expect GeneralSecurityException: " + e);
}
}
use of com.google.crypto.tink.subtle.Ed25519Verify in project tink by google.
the class Ed25519PrivateKeyManagerTest method testDeriveKeySignVerify.
@Test
public void testDeriveKeySignVerify() throws Exception {
byte[] keyMaterial = Random.randBytes(100);
Ed25519PrivateKey key = factory.deriveKey(Ed25519KeyFormat.newBuilder().setVersion(0).build(), new ByteArrayInputStream(keyMaterial));
PublicKeySign signer = manager.getPrimitive(key, PublicKeySign.class);
PublicKeyVerify verifier = new Ed25519Verify(key.getPublicKey().getKeyValue().toByteArray());
byte[] message = Random.randBytes(135);
verifier.verify(signer.sign(message), message);
}
Aggregations