/** * @return a PublicKeySign primitive from a {@code keysetHandle}. * @throws GeneralSecurityException */ public static PublicKeySign getPrimitive(KeysetHandle keysetHandle) throws GeneralSecurityException { return getPrimitive(keysetHandle, /* keyManager= */ null); }
/** * @return a PublicKeyVerify primitive from a {@code keysetHandle}. * @throws GeneralSecurityException */ public static PublicKeyVerify getPrimitive(KeysetHandle keysetHandle) throws GeneralSecurityException { return getPrimitive(keysetHandle, /* keyManager= */ null); }
@Override public MessageLite newKey(ByteString unused) throws GeneralSecurityException { return newKey(); }
/** * Tries to register with the {@link Registry} all instances of {@link * com.google.crypto.tink.Catalogue} needed to handle PublicKeySign and PublicKeyVerify key types * supported in Tink. * * @deprecated use {@link #register} */ @Deprecated public static void init() throws GeneralSecurityException { register(); }
private KeyManager<PublicKeySign> publicKeySignKeyManager(String typeUrl) throws GeneralSecurityException { switch (typeUrl) { case EcdsaSignKeyManager.TYPE_URL: return new EcdsaSignKeyManager(); case Ed25519PrivateKeyManager.TYPE_URL: return new Ed25519PrivateKeyManager(); default: throw new GeneralSecurityException( String.format("No support for primitive 'PublicKeySign' with key type '%s'.", typeUrl)); } } }
private KeyManager<PublicKeyVerify> publicKeyVerifyKeyManager(String typeUrl) throws GeneralSecurityException { switch (typeUrl) { case EcdsaVerifyKeyManager.TYPE_URL: return new EcdsaVerifyKeyManager(); case Ed25519PublicKeyManager.TYPE_URL: return new Ed25519PublicKeyManager(); default: throw new GeneralSecurityException( String.format( "No support for primitive 'PublicKeyVerify' with key type '%s'.", typeUrl)); } } }
/** * Tries to register with the {@link Registry} all instances of {@link * com.google.crypto.tink.Catalogue} needed to handle PublicKeySign and PublicKeyVerify key types * supported in Tink. * * @since 1.2.0 */ public static void register() throws GeneralSecurityException { Registry.addCatalogue(PUBLIC_KEY_SIGN_CATALOGUE_NAME, new PublicKeySignCatalogue()); Registry.addCatalogue(PUBLIC_KEY_VERIFY_CATALOGUE_NAME, new PublicKeyVerifyCatalogue()); Config.register(LATEST); } }
/** @param serializedKey serialized {@code EcdsaPublicKey} proto */ @Override public PublicKeyVerify getPrimitive(ByteString serializedKey) throws GeneralSecurityException { try { EcdsaPublicKey pubKey = EcdsaPublicKey.parseFrom(serializedKey); return getPrimitive(pubKey); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected serialized EcdsaPublicKey proto", e); } }
@Override public PublicKeyVerify getPrimitive(ByteString serialized) throws GeneralSecurityException { try { Ed25519PublicKey keyProto = Ed25519PublicKey.parseFrom(serialized); return getPrimitive(keyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("invalid Ed25519 public key", e); } }
@Override public PublicKeySign getPrimitive(ByteString serialized) throws GeneralSecurityException { try { Ed25519PrivateKey keyProto = Ed25519PrivateKey.parseFrom(serialized); return getPrimitive(keyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("invalid Ed25519 private key", e); } }
/** @param serializedKey serialized {@code EcdsaPrivateKey} proto */ @Override public PublicKeySign getPrimitive(ByteString serializedKey) throws GeneralSecurityException { try { EcdsaPrivateKey privKeyProto = EcdsaPrivateKey.parseFrom(serializedKey); return getPrimitive(privKeyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected serialized EcdsaPrivateKey proto", e); } }
/** * @param serializedKeyFormat serialized {@code EcdsaKeyFormat} proto * @return new {@code EcdsaPrivateKey} proto */ @Override public MessageLite newKey(ByteString serializedKeyFormat) throws GeneralSecurityException { try { EcdsaKeyFormat ecdsaKeyFormat = EcdsaKeyFormat.parseFrom(serializedKeyFormat); return newKey(ecdsaKeyFormat); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected EcdsaKeyFormat proto", e); } }
private void validate(EcdsaPublicKey pubKey) throws GeneralSecurityException { Validators.validateVersion(pubKey.getVersion(), VERSION); SigUtil.validateEcdsaParams(pubKey.getParams()); } }
private byte[] sign(KeysetHandle privateKeysetHandle) throws GeneralSecurityException { PublicKeySign signer = PublicKeySignFactory.getPrimitive(privateKeysetHandle); return signer.sign(INITIAL_TEXT.getBytes()); }
static PublicKeyVerify createTestSenderVerifier() throws GeneralSecurityException, IOException { KeysetHandle verificationKeyHandle = CleartextKeysetHandle .read(BinaryKeysetReader.withBytes(TestUtils.getBytes("verification_key.dat"))); return PublicKeyVerifyFactory.getPrimitive(verificationKeyHandle); }
/** * Init SignatureConfig in the Tink library. */ private EcdsaDemo() { try { SignatureConfig.register(); } catch (GeneralSecurityException ex) { log.error("Failed to initialize Tink", ex); } }
@Override public MessageLite newKey(MessageLite unused) throws GeneralSecurityException { return newKey(); }
/** * Constructs a new RSA-ECDSA EncrypterManager. * * <p>Please note that the {@link InputStream} {@code senderSigningKey} will not be closed. * * @param senderSigningKey the serialized Tink signing key. * @throws GeneralSecurityException if the initialization fails. * @throws IOException if the given sender signing key cannot be read. */ public RsaEcdsaEncrypterManager(InputStream senderSigningKey) throws GeneralSecurityException, IOException { KeysetHandle signingKeyHandle = CleartextKeysetHandle .read(BinaryKeysetReader.withInputStream(senderSigningKey)); senderSigner = PublicKeySignFactory.getPrimitive(signingKeyHandle); }
/** * Tries to register with the {@link Registry} all instances of {@link * com.google.crypto.tink.Catalogue} and {@link com.google.crypto.tink.KeyManager} needed to * handle all key types supported in Tink. * * @since 1.2.0 */ public static void register() throws GeneralSecurityException { DeterministicAeadConfig.register(); HybridConfig.register(); // includes Aead and Mac SignatureConfig.register(); } }
static PublicKeySign createTestSenderSigner() throws GeneralSecurityException, IOException { KeysetHandle signingKeyHandle = CleartextKeysetHandle .read(BinaryKeysetReader.withBytes(TestUtils.getBytes("signing_key.dat"))); return PublicKeySignFactory.getPrimitive(signingKeyHandle); }