# Plugin cipher & Value of a field

**URL:** <https://discuss.elastic.co/t/plugin-cipher-value-of-a-field/236709>\
**Category:** Logstash\
**Created:** [June 11, 2020, 1:24pm UTC](https://discuss.elastic.co/t/plugin-cipher-value-of-a-field/236709 "2020-06-11T13:24:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florent\_Fauvin](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Florent\_Fauvin](https://discuss.elastic.co/u/Florent_Fauvin)\
**Post date:** [June 11, 2020, 1:24pm UTC](https://discuss.elastic.co/t/plugin-cipher-value-of-a-field/236709/1 "2020-06-11T13:24:05Z")

</div>

Hello,

I am trying to use the value of a field, but I do not know why, I have the impression that the cipher plugin cannot read it. Could you help me figure out what's wrong please?

Below, I stored the value of "algorithm" in "[@metadata] [algorithm]" :

OK :

```
input { stdin { } }

filter {

  mutate {
    add_field => { "[@metadata][encrypted]" => "gKHInKhQooaPgF7m99B465HN4Wi5+ESCjq5LTc69h/I5+/fSsEbxGjk0NpiNrpH8" }
  }

  cipher {
    algorithm => "aes-256-cbc"
      iv_random_length => 16
      key => "12345678901234567890123456789012"
      key_size => 32
      mode => "decrypt"
      source => "[@metadata][encrypted]"
      target => "[@metadata][decrypted]"
  }
}

output { stdout { codec => rubydebug { metadata => true } } }

```

NOT OK : 🙁

```
input { stdin { } }

filter {

  mutate {
    add_field => { 
    "[@metadata][encrypted]" => "gKHInKhQooaPgF7m99B465HN4Wi5+ESCjq5LTc69h/I5+/fSsEbxGjk0NpiNrpH8" 
    "[@metadata][algorithm]" => "aes-256-cbc"
    }
  }

  cipher {
    algorithm => "%{[@metadata][algorithm]}"
      iv_random_length => 16
      key => "12345678901234567890123456789012"
      key_size => 32
      mode => "decrypt"
      source => "[@metadata][encrypted]"
      target => "[@metadata][decrypted]"
  }
}

output { stdout { codec => rubydebug { metadata => true } } } 

```

Thank you so much,

Florent

---

<div class="post-metadata">

**Author:** ![Florent\_Fauvin](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Florent\_Fauvin](https://discuss.elastic.co/u/Florent_Fauvin)\
**Post date:** [June 11, 2020, 1:28pm UTC](https://discuss.elastic.co/t/plugin-cipher-value-of-a-field/236709/2 "2020-06-11T13:28:36Z")

</div>

`[ERROR] 2020-06-11 15:14:22.767 [[main]-pipeline-manager] javapipeline - Pipeline aborted due to error {:pipeline_id=>"main", :exception=>#<OpenSSL::Cipher::CipherError: unsupported cipher algorithm (%{[@METADATA][ALGORITHM]}/CBC/PKCS5Padding)>`

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [June 11, 2020, 2:10pm UTC](https://discuss.elastic.co/t/plugin-cipher-value-of-a-field/236709/3 "2020-06-11T14:10:10Z")

</div>

> [@Florent\_Fauvin](#):
>
> I am trying to use the value of a field, but I do not know why, I have the impression that the cipher plugin cannot read it.

The cipher filter does not sprintf the algorithm. It just [uses](https://github.com/logstash-plugins/logstash-filter-cipher/blob/abc58e5a09ba0bb18bb99d532e994a7533368212/lib/logstash/filters/cipher.rb#L192) the literal value.

---

<div class="post-metadata">

**Author:** ![Florent\_Fauvin](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Florent\_Fauvin](https://discuss.elastic.co/u/Florent_Fauvin)\
**Post date:** [June 11, 2020, 2:14pm UTC](https://discuss.elastic.co/t/plugin-cipher-value-of-a-field/236709/4 "2020-06-11T14:14:12Z")

</div>

> [@Badger](#):
>
> sprintf

What do you mean ?

I must write a "string" directly, and that I cannot use the value of a field ?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [June 11, 2020, 2:19pm UTC](https://discuss.elastic.co/t/plugin-cipher-value-of-a-field/236709/5 "2020-06-11T14:19:59Z")

</div>

> [@Florent\_Fauvin](#):
>
> I must write a "string" directly, and that I cannot use the value of a field ?

That is correct. A reference to a field like

```
algorithm => "%{[@metadata][algorithm]}"

```

is called a sprintf reference, and the filter or output would resolve it by calling a method called sprintf. That is typically done on fields that the plugin is setting, not inputs to the plugin.

---

<div class="post-metadata">

**Author:** ![Florent\_Fauvin](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@Florent\_Fauvin](https://discuss.elastic.co/u/Florent_Fauvin)\
**Post date:** [June 11, 2020, 2:24pm UTC](https://discuss.elastic.co/t/plugin-cipher-value-of-a-field/236709/6 "2020-06-11T14:24:39Z")

</div>

OK !

I want to use cipher plugin more than once in my pipeline, and I don't want to write "algorithm / key / iv" every time. I wanted to centralize these parameters at the beginning of the file.

I feel like I can't do it, can I ?  
Do you have another idea to avoid duplicating all these parameters throughout the file?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [June 11, 2020, 3:13pm UTC](https://discuss.elastic.co/t/plugin-cipher-value-of-a-field/236709/7 "2020-06-11T15:13:40Z")

</div>

> [@Florent\_Fauvin](#):
>
> Do you have another idea to avoid duplicating all these parameters throughout the file?

No, I cannot think of a way to avoid the duplication.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 9, 2020, 3:13pm UTC](https://discuss.elastic.co/t/plugin-cipher-value-of-a-field/236709/8 "2020-07-09T15:13:41Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
