AesCtrHmacAeadKeyManager() throws GeneralSecurityException { Registry.registerKeyManager(new AesCtrKeyManager()); }
/** @param serializedKey serialized {@code AesCtrKey} proto */ @Override public AesCtrJceCipher getPrimitive(ByteString serializedKey) throws GeneralSecurityException { try { AesCtrKey keyProto = AesCtrKey.parseFrom(serializedKey); return getPrimitive(keyProto); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected serialized AesCtrKey proto", e); } }
/** * @param serializedKeyFormat serialized {@code AesCtrKeyFormat} proto * @return new {@code AesCtrKey} proto */ @Override public MessageLite newKey(ByteString serializedKeyFormat) throws GeneralSecurityException { try { AesCtrKeyFormat format = AesCtrKeyFormat.parseFrom(serializedKeyFormat); return newKey(format); } catch (InvalidProtocolBufferException e) { throw new GeneralSecurityException("expected serialized AesCtrKeyFormat proto", e); } }
/** @param key {@code AesCtrKey} proto */ @Override public AesCtrJceCipher getPrimitive(MessageLite key) throws GeneralSecurityException { if (!(key instanceof AesCtrKey)) { throw new GeneralSecurityException("expected AesCtrKey proto"); } AesCtrKey keyProto = (AesCtrKey) key; validate(keyProto); return new AesCtrJceCipher( keyProto.getKeyValue().toByteArray(), keyProto.getParams().getIvSize()); }
private void validate(AesCtrKeyFormat format) throws GeneralSecurityException { Validators.validateAesKeySize(format.getKeySize()); validate(format.getParams()); }
/** * @param keyFormat {@code AesCtrKeyFormat} proto * @return new {@code AesCtrKey} proto */ @Override public MessageLite newKey(MessageLite keyFormat) throws GeneralSecurityException { if (!(keyFormat instanceof AesCtrKeyFormat)) { throw new GeneralSecurityException("expected AesCtrKeyFormat proto"); } AesCtrKeyFormat format = (AesCtrKeyFormat) keyFormat; validate(format); return AesCtrKey.newBuilder() .setParams(format.getParams()) .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .setVersion(VERSION) .build(); }
/** * @param serializedKeyFormat serialized {@code AesCtrKeyFormat} proto * @return {@code KeyData} proto with a new {@code AesCtrKey} proto */ @Override public KeyData newKeyData(ByteString serializedKeyFormat) throws GeneralSecurityException { AesCtrKey key = (AesCtrKey) newKey(serializedKeyFormat); return KeyData.newBuilder() .setTypeUrl(TYPE_URL) .setValue(key.toByteString()) .setKeyMaterialType(KeyData.KeyMaterialType.SYMMETRIC) .build(); }
private void validate(AesCtrKey key) throws GeneralSecurityException { Validators.validateVersion(key.getVersion(), VERSION); Validators.validateAesKeySize(key.getKeyValue().size()); validate(key.getParams()); }