# Encryption/decryption package

**URL:** <https://discourse.julialang.org/t/encryption-decryption-package/59581>\
**Category:** Data\
**Created:** [April 19, 2021, 7:33am UTC](https://discourse.julialang.org/t/encryption-decryption-package/59581 "2021-04-19T07:33:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laco\_Kovac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laco_kovac/32/20684_2.png) [@Laco\_Kovac](https://discourse.julialang.org/u/Laco_Kovac)\
**Post date:** [April 19, 2021, 7:33am UTC](https://discourse.julialang.org/t/encryption-decryption-package/59581/1 "2021-04-19T07:33:18Z")

</div>

I have quite big String (~20M). It needs to be encrypted and downloaded as a file and then, eventually, uploaded back, decrypted & used. Encryption key or password belongs to the application/server (i.e. it is not specific to the user logged in).

What would be the best and simple to use package to achieve this?

Thank you

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [April 19, 2021, 8:52am UTC](https://discourse.julialang.org/t/encryption-decryption-package/59581/2 "2021-04-19T08:52:46Z")

</div>

You can use `OpenSSL`:

```julia
using OpenSSL_jll

passphrase = "hunter2"
encrypter = `$(openssl()) enc -aes-256-cbc -pbkdf2 -pass pass:$(passphrase)`
decrypter = `$(openssl()) enc -d -aes-256-cbc -pbkdf2 -pass pass:$(passphrase)`

open("hello.txt", "r") do io
    open("hello.txt.encrypted", "w") do io2
        run(pipeline(encrypter, stdin=io, stdout=io2))
    end
end

open("hello.txt.encrypted", "r") do io
    open("hello.txt.decrypted", "w") do io2
        run(pipeline(decrypter, stdin=io, stdout=io2))
    end
end

```

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [April 19, 2021, 8:54am UTC](https://discourse.julialang.org/t/encryption-decryption-package/59581/3 "2021-04-19T08:54:45Z")

</div>

_Age_ is popular. It can be used on the command line. It doesn’t require configuration, so it’s harder to make a mistake with it.

> **[GitHub - FiloSottile/age: A simple, modern and secure encryption tool (and Go...](https://github.com/FiloSottile/age)**
>
> A simple, modern and secure encryption tool (and Go library) with small explicit keys, no config options, and UNIX-style composability. - GitHub - FiloSottile/age: A simple, modern and secure encry...

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [April 19, 2021, 7:10pm UTC](https://discourse.julialang.org/t/encryption-decryption-package/59581/4 "2021-04-19T19:10:09Z")

</div>

Alternatively, it is also possible to use [rclone](https://rclone.org/). The following function decrypts a folder which was encrypted via rclone and does so without using a rclone config file. This makes it easier to use in things like CI jobs

```julia
function decrypt_data()
    crypt_password = ENV["OBSCURED_ENCRYPTION_PASSWORD"]
    from = joinpath(homedir(), "data")
    to = joinpath(homedir(), "decrypted-data")
    args = [
        "--crypt-password=$crypt_password",
        "--crypt-remote=/",
        "--crypt-filename-encryption=off",
        "--crypt-directory-name-encryption=false",
        "copy",
        ":crypt:$from",
        to
    ]
    Rclone_jll.rclone() do bin
        run(`$bin $args`)
    end
end

```

---

<div class="post-metadata">

**Author:** ![Laco\_Kovac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laco_kovac/32/20684_2.png) [@Laco\_Kovac](https://discourse.julialang.org/u/Laco_Kovac)\
**Post date:** [April 24, 2021, 8:45am UTC](https://discourse.julialang.org/t/encryption-decryption-package/59581/5 "2021-04-24T08:45:25Z")

</div>

> [@fredrikekre](#):
>
> ```julia
> passphrase = "hunter2"
> encrypter = `$(openssl()) enc -aes-256-cbc -pbkdf2 -pass pass:$(passphrase)`
> decrypter = `$(openssl()) enc -d -aes-256-cbc -pbkdf2 -pass pass:$(passphrase)`
> 
> open("hello.txt", "r") do io
> open("hello.txt.encrypted", "w") do io2
> run(pipeline(encrypter, stdin=io, stdout=io2))
> end
> end
> 
> ```

Thank you, but openssl() requires ::Function parameter:

```julia
julia> encrypter = `$(openssl()) enc -aes-256-cbc -pbkdf2 -pass pass:$(passphrase)`
ERROR: MethodError: no method matching openssl()
Closest candidates are:
  openssl(::Function; adjust_PATH, adjust_LIBPATH) at .julia\packages\JLLWrappers\bkwIo\src\products\executable_generators.jl:5

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [April 24, 2021, 8:48am UTC](https://discourse.julialang.org/t/encryption-decryption-package/59581/6 "2021-04-24T08:48:22Z")

</div>

You probably run an old version of `OpenSSL_jll` then. I used version v1.1.1+6.

---

<div class="post-metadata">

**Author:** ![Laco\_Kovac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laco_kovac/32/20684_2.png) [@Laco\_Kovac](https://discourse.julialang.org/u/Laco_Kovac)\
**Post date:** [April 24, 2021, 8:55am UTC](https://discourse.julialang.org/t/encryption-decryption-package/59581/7 "2021-04-24T08:55:50Z")

</div>

Me too…

```julia
(@v1.5) pkg> add OpenSSL_jll
   Updating registry at `.julia\registries\General`
  Resolving package versions...
Updating `.julia\environments\v1.5\Project.toml`
  [458c3c95] + OpenSSL_jll v1.1.1+6
Updating `.julia\environments\v1.5\Manifest.toml`
  [458c3c95] + OpenSSL_jll v1.1.1+6

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [April 24, 2021, 10:01am UTC](https://discourse.julialang.org/t/encryption-decryption-package/59581/8 "2021-04-24T10:01:37Z")

</div>

Looks like you are usting Julia 1.5 though.

---

<div class="post-metadata">

**Author:** ![Laco\_Kovac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laco_kovac/32/20684_2.png) [@Laco\_Kovac](https://discourse.julialang.org/u/Laco_Kovac)\
**Post date:** [April 24, 2021, 10:32am UTC](https://discourse.julialang.org/t/encryption-decryption-package/59581/9 "2021-04-24T10:32:29Z")

</div>

Yes. I cannot upgrade myself; whole team would have.  
Julia 1.5 will not work with OpenSSL\_jll v1.1.1+6 ?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [April 24, 2021, 10:40am UTC](https://discourse.julialang.org/t/encryption-decryption-package/59581/10 "2021-04-24T10:40:24Z")

</div>

Ok, here is the Julia 1.5 version:

```julia
using OpenSSL_jll

passphrase = "hunter2"

open("hello.txt", "r") do io
    open("hello.txt.encrypted", "w") do io2
        openssl() do prog
            encrypter = `$(prog) enc -aes-256-cbc -pbkdf2 -pass pass:$(passphrase)`
            run(pipeline(encrypter, stdin=io, stdout=io2))
        end
    end
end

open("hello.txt.encrypted", "r") do io
    open("hello.txt.decrypted", "w") do io2
        openssl() do prog
            decrypter = `$(prog) enc -d -aes-256-cbc -pbkdf2 -pass pass:$(passphrase)`
            run(pipeline(decrypter, stdin=io, stdout=io2))
        end
    end
end

```
