# Way to load PEM certificates from String into a SSL Context

**URL:** https://forum.crystal-lang.org/t/way-to-load-pem-certificates-from-string-into-a-ssl-context/6974
**Category:** Help & Support
**Created:** [June 27, 2024, 2:15pm UTC](https://forum.crystal-lang.org/t/way-to-load-pem-certificates-from-string-into-a-ssl-context/6974 "2024-06-27T14:15:33Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![luislavena](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/luislavena/32/572_2.png) [@luislavena](https://forum.crystal-lang.org/u/luislavena)
#### Post date: [June 27, 2024, 2:15pm UTC](https://forum.crystal-lang.org/t/way-to-load-pem-certificates-from-string-into-a-ssl-context/6974/1 "2024-06-27T14:15:33Z")

</div>

Hello folks,

I was looking for ways to load PEM certificates from String into a `OpenSSL::SSL::Context` (specifically Client one) for certificate pinning, but I couldn’t find a clear mechanism for this.

While I know there is `#ca_certificates=` and `#ca_certificates_path=`, they all treat with files in the filesystem, but none about loading them from a string from memory.

I found [`OpenSSL::X509::Certificate.from_der?`](https://github.com/crystal-lang/crystal/blob/master/src/openssl/x509/certificate.cr#L31-L42), but the only test is from Windows and this is expecting the cert to be in DER format, which means the PEM must be converted to DER (binary), making it a bit more complicated to bundle (via macro) into your application source.

Not to mention, no mechanism to add that certificate into that context 😅

Any ideas?

Thank you in advance!

❤ ❤ ❤
