use of com.google.crypto.tink.subtle.Ed25519Sign 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.Ed25519Sign in project tink by google.
the class Ed25519PrivateKeyManager method getPrimitive.
@Override
public PublicKeySign getPrimitive(MessageLite key) throws GeneralSecurityException {
if (!(key instanceof Ed25519PrivateKey)) {
throw new GeneralSecurityException("expected Ed25519PrivateKey proto");
}
Ed25519PrivateKey keyProto = (Ed25519PrivateKey) key;
validate(keyProto);
return new Ed25519Sign(keyProto.getKeyValue().toByteArray());
}
Aggregations