use of com.google.crypto.tink.PublicKeySign in project tink by google.
the class RsaSsaPssVerifyKeyManagerTest method createPrimitive.
@Test
public void createPrimitive() throws Exception {
if (TestUtil.isTsan()) {
// factory.createKey is too slow in Tsan.
return;
}
RsaSsaPssKeyFormat keyFormat = RsaSsaPssKeyFormat.newBuilder().setParams(RsaSsaPssParams.newBuilder().setSigHash(HashType.SHA256).setMgf1Hash(HashType.SHA256).setSaltLength(32)).setModulusSizeInBits(3072).setPublicExponent(ByteString.copyFrom(RSAKeyGenParameterSpec.F4.toByteArray())).build();
RsaSsaPssPrivateKey privateKey = factory.createKey(keyFormat);
RsaSsaPssPublicKey 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);
}
use of com.google.crypto.tink.PublicKeySign 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);
}
use of com.google.crypto.tink.PublicKeySign 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.PublicKeySign in project tink by google.
the class SignatureServiceImpl method sign.
/**
* Signs a message.
*/
@Override
public void sign(SignatureSignRequest request, StreamObserver<SignatureSignResponse> responseObserver) {
SignatureSignResponse response;
try {
KeysetHandle privateKeysetHandle = CleartextKeysetHandle.read(BinaryKeysetReader.withBytes(request.getPrivateKeyset().toByteArray()));
PublicKeySign signer = privateKeysetHandle.getPrimitive(PublicKeySign.class);
byte[] signatureValue = signer.sign(request.getData().toByteArray());
response = SignatureSignResponse.newBuilder().setSignature(ByteString.copyFrom(signatureValue)).build();
} catch (GeneralSecurityException | InvalidProtocolBufferException e) {
response = SignatureSignResponse.newBuilder().setErr(e.toString()).build();
} catch (IOException e) {
responseObserver.onError(Status.UNKNOWN.withDescription(e.getMessage()).asException());
return;
}
responseObserver.onNext(response);
responseObserver.onCompleted();
}
use of com.google.crypto.tink.PublicKeySign in project tink by google.
the class PublicKeySignCli method main.
public static void main(String[] args) throws Exception {
if (args.length != 3) {
System.out.println("Usage: PublicKeySignCli keyset-file message-file output-file");
System.exit(1);
}
String keysetFilename = args[0];
String messageFilename = args[1];
String outputFilename = args[2];
System.out.println("Using keyset from file " + keysetFilename + " to sign message from " + messageFilename + ".");
System.out.println("The resulting signature will be written to file " + outputFilename);
// Init Tink.
CliUtil.initTink();
// Read the keyset.
System.out.println("Reading the keyset...");
KeysetHandle keysetHandle = CliUtil.readKeyset(keysetFilename);
// Get the primitive.
System.out.println("Getting the primitive...");
PublicKeySign pkSign = PublicKeySignFactory.getPrimitive(keysetHandle);
// Read the message.
byte[] message = CliUtil.read(messageFilename);
// Compute the signature.
System.out.println("Signing...");
byte[] signature = pkSign.sign(message);
// Write the signature to the output file.
CliUtil.write(signature, outputFilename);
System.out.println("All done.");
}
Aggregations