JuliaWeb / JuliaWeb/OpenSSL.jl

How to write key pair to a string?

Open
#39 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
19
Forks
16
PR merge metrics
No merged PRs in 30d

Description

Hello, I want to write a key pair EvpPKey to an IOBuffer in PEM format. How can I do that?

I assumed this would work:
```julia
using OpenSSL

rsa_key = OpenSSL.EvpPKey(rsa_generate_key())
io = IOBuffer()
write(io, rsa_key)
```

but it throws an error
```
OpenSSL.OpenSSLError("404824FD01000000:error:04880007:PEM routines:PEM_write_bio:BUF lib:crypto/pem/pem_lib.c:664:\n")
```

For the public key I wrote this function
```julia
function write_pubkey(io::IO, evp_pkey::OpenSSL.EvpPKey)
bio = OpenSSL.BIO(io)
GC.@preserve bio io begin
# int PEM_write_bio_PUBKEY(BIO *bp, EVP_PKEY *x);
if ccall(
(:PEM_write_bio_PUBKEY, libcrypto),
Cint,
(OpenSSL.BIO, OpenSSL.EvpPKey),
bio,
evp_pkey) != 1
throw(OpenSSL.OpenSSLError())
end
end
end
```

```julia
using OpenSSL

rsa_key = OpenSSL.EvpPKey(rsa_generate_key())
io = IOBuffer()
write_pubkey(io, rsa_key)
```

and get the same error
```
OpenSSL.OpenSSLError("404824FD01000000:error:04880007:PEM routines:PEM_write_bio:BUF lib:crypto/pem/pem_lib.c:664:\n")
```

Is there something I'm missing when it comes to configuring the IOBuffer and the OpenSSL.BIO?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.