private KeysetHandle generateKey() throws GeneralSecurityException { return KeysetHandle.generateNew(MacKeyTemplates.HMAC_SHA256_128BITTAG); } }
private KeysetHandle generatePublicKey(KeysetHandle privateKeysetHandle) throws GeneralSecurityException { return privateKeysetHandle.getPublicKeysetHandle(); }
/** * Tries to create a {@link KeysetHandle} from an encrypted keyset obtained via {@code reader}. * * <p>Users that need to load cleartext keysets can use {@link CleartextKeysetHandle}. * * @return a new {@link KeysetHandle} from {@code encryptedKeysetProto} that was encrypted with * {@code masterKey} * @throws GeneralSecurityException if cannot decrypt the keyset or it doesn't contain encrypted * key material */ public static final KeysetHandle read(KeysetReader reader, Aead masterKey) throws GeneralSecurityException, IOException { EncryptedKeyset encryptedKeyset = reader.readEncrypted(); assertEnoughEncryptedKeyMaterial(encryptedKeyset); return new KeysetHandle(decrypt(encryptedKeyset, masterKey)); }
/** * @return a new {@link KeysetHandle} from a {@code keyset}. * @throws GeneralSecurityException */ static final KeysetHandle fromKeyset(Keyset keyset) throws GeneralSecurityException { assertEnoughKeyMaterial(keyset); return new KeysetHandle(keyset); }
private static void generateEcdsaKeyPair(File publicKeyFile, File privatekeyFile) throws GeneralSecurityException, IOException { KeysetHandle privateKeyHandle = KeysetHandle.generateNew(SIGNATURE_KEY_TEMPLATE); CleartextKeysetHandle.write(privateKeyHandle, BinaryKeysetWriter.withFile(privatekeyFile)); KeysetHandle publicKeyHandle = privateKeyHandle.getPublicKeysetHandle(); CleartextKeysetHandle.write(publicKeyHandle, BinaryKeysetWriter.withFile(publicKeyFile)); } }
/** * Extracts and returns the string representation of the {@link * com.google.crypto.tink.proto.KeysetInfo} of the managed keyset. */ @Override public String toString() { return getKeysetInfo().toString(); }
/** * If the managed keyset contains private keys, returns a {@link KeysetHandle} of the public keys. * * @throws GenernalSecurityException if the managed keyset is null or if it contains any * non-private keys. */ public KeysetHandle getPublicKeysetHandle() throws GeneralSecurityException { if (keyset == null) { throw new GeneralSecurityException("cleartext keyset is not available"); } Keyset.Builder keysetBuilder = Keyset.newBuilder(); for (Keyset.Key key : keyset.getKeyList()) { KeyData keyData = createPublicKeyData(key.getKeyData()); keysetBuilder.addKey(Keyset.Key.newBuilder().mergeFrom(key).setKeyData(keyData).build()); } keysetBuilder.setPrimaryKeyId(keyset.getPrimaryKeyId()); return new KeysetHandle(keysetBuilder.build()); }
/** Decrypts the encrypted keyset with the {@link Aead} master key. */ private static Keyset decrypt(EncryptedKeyset encryptedKeyset, Aead masterKey) throws GeneralSecurityException { try { Keyset keyset = Keyset.parseFrom( masterKey.decrypt( encryptedKeyset.getEncryptedKeyset().toByteArray(), /* associatedData= */ new byte[0])); // check emptiness here too, in case the encrypted keys unwrapped to nothing? assertEnoughKeyMaterial(keyset); return keyset; } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("invalid keyset, corrupted key material"); } }
/** * Optional step to disable the original key. */ private KeysetHandle disableOriginalKey(KeysetHandle keysetHandle) throws GeneralSecurityException { return KeysetManager.withKeysetHandle(keysetHandle).disable(keysetHandle.getKeysetInfo().getKeyInfo(0).getKeyId()).getKeysetHandle(); }
private KeysetHandle generatePrivateKey() throws GeneralSecurityException { return KeysetHandle.generateNew(HybridKeyTemplates.ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM); }
private KeysetHandle generatePublicKey(KeysetHandle privateKeysetHandle) throws GeneralSecurityException { return privateKeysetHandle.getPublicKeysetHandle(); }
private KeysetHandle generatePrivateKey() throws GeneralSecurityException { return KeysetHandle.generateNew(SignatureKeyTemplates.ECDSA_P256); }
private KeysetHandle generatePublicKey(KeysetHandle privateKeysetHandle) throws GeneralSecurityException { return privateKeysetHandle.getPublicKeysetHandle(); }
private KeysetHandle generatePrivateKey() throws GeneralSecurityException { return KeysetHandle.generateNew(HybridKeyTemplates.ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM); }
/** * Stores the public keyset in the projects resources/keysets directory if it does not exist yet. * * @throws IOException Failure during saving * @throws GeneralSecurityException Failure during keyset generation */ private void generateAndStorePublicKey(KeysetHandle privateKeysetHandle) throws IOException, GeneralSecurityException { KeysetHandle keysetHandle = privateKeysetHandle.getPublicKeysetHandle(); File keysetFile = new File(PUBLIC_KEYSET_FILENAME); if (!keysetFile.exists()) { CleartextKeysetHandle.write(keysetHandle, JsonKeysetWriter.withFile(keysetFile)); } }
private KeysetHandle generateKey() throws GeneralSecurityException { return KeysetHandle.generateNew(AeadKeyTemplates.AES128_GCM); }
/** * Stores the private keyset in the projects resources/keysets directory if it does not exist yet. * * @throws IOException Failure during saving * @throws GeneralSecurityException Failure during keyset generation */ private void generateAndStorePrivateKey() throws IOException, GeneralSecurityException { KeysetHandle keysetHandle = KeysetHandle.generateNew(HybridKeyTemplates.ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM); File keysetFile = new File(PRIVATE_KEYSET_FILENAME); if (!keysetFile.exists()) { CleartextKeysetHandle.write(keysetHandle, JsonKeysetWriter.withFile(keysetFile)); } }
/** * Stores the keyset in the projects resources/keysets directory if it does not exist yet. * * @throws IOException Failure during saving * @throws GeneralSecurityException Failure during keyset generation */ private void generateAndStoreKey() throws IOException, GeneralSecurityException { KeysetHandle keysetHandle = KeysetHandle.generateNew(AeadKeyTemplates.AES128_GCM); File keysetFile = new File(KEYSET_FILENAME); if (!keysetFile.exists()) { CleartextKeysetHandle.write(keysetHandle, JsonKeysetWriter.withFile(keysetFile)); } }
KeysetHandle symmetricKeyHandle = KeysetHandle.generateNew(SYMMETRIC_KEY_TEMPLATE); ByteArrayOutputStream symmetricKeyOutputStream = new ByteArrayOutputStream(); try {
KeysetHandle symmetricKeyHandle = KeysetHandle.generateNew(SYMMETRIC_KEY_TEMPLATE); ByteArrayOutputStream symmetricKeyOutputStream = new ByteArrayOutputStream(); try {