TIL: Asymmetric Cryptography in Go

I’ve been implementing a feature at work that involves asymmetric cryptography. It has been a pretty fun exercise in stitching together Go APIs while reading about best practices.

Here’s a few things I’ve learned over the last couple of days:

  • Go’s cryptography isn’t FIPS compliant.

  • Go has an implementation of ECDSA (Elliptic Curve Digital Signature Algorithm), but it doesn’t have any elliptic curve asymmetric encryption algorithms.

    • The best asymmetric algorithm that Go has is RSA
  • Go has an implementation of PEM (Privacy Enhanced Mail) data encoding which can be used to encode public/private in a familiar format. You’ve probably seen this format with SSH keys:

    -----BEGIN PUBLIC KEY-----
    MIIEpAIBAAKCAQEAuOuUOwNRMbqc0jMEVTOyKuVUu0bk0zD5iwIggBHpDhV58DSJ
    SK7OFIFHVMy6FKg2B3Y50srfVJ45OE9Vsb9hfErUNA/PB5meHGEI+yPKeni4GAfy
    <and so on>
    -----END PUBLIC KEY-----
    
  • The legacy PEM format has support for plaintext headers like so:

    -----BEGIN PUBLIC KEY-----
    Data: Some value I don't mind being plaintext
    
    MIIEpAIBAAKCAQEAuOuUOwNRMbqc0jMEVTOyKuVUu0bk0zD5iwIggBHpDhV58DSJ
    SK7OFIFHVMy6FKg2B3Y50srfVJ45OE9Vsb9hfErUNA/PB5meHGEI+yPKeni4GAfy
    <and so on>
    -----END PUBLIC KEY-----
    
    • The newer RFC eplicitly doesn’t support headers, though:

      Unlike legacy PEM encoding RFC1421, OpenPGP ASCII armor, and the OpenSSH key file format, textual encoding does not define or permit headers to be encoded alongside the data.

  • Go’s APIs for encrypting, decrypting, signing, and verifying data are quite pleasant to use!

  • When signing data, Go will first have you run that data through a hash algorithm (e.g. SHA256). This actually makes quite a bit of sense, and it helps me better understand why secure hashing is important for cryptography.

  • OWASP (Open Worldwide Application Security Project) has a great section on encryption algorithms which can help guide those less familiar with the specifics of encryption.

  • There are a few algorithms for signing and encryption data with RSA. Go implements PKCS1v15 and OAEP for encryption, and PKCS1v15 and PSS for signing.

While I’m generally not a huge fan of Go, I do think the standard library has some nice packages, and the encryption library is definitely one of them.

Recent posts from blogs that I like

Xecast Episode 1: Origins and Techaro

Your browser does not support the audio element.

Download MP3

Also catch Xecast on YouTube (I'll make a proper podcast feed soon, trying to de-scope so I can actually get things done).

<Mimi>

These show notes were generated using Google Gemini 1.5 Pro. Should this podcast take off, we'll find a be...

via Xe Iaso

What can I do if IMlangConvertCharset is unable to convert from code page 28591 directly to UTF-8?

You can do the conversion in two steps using things you already have. The post What can I do if IMlangConvertCharset is unable to convert from code page 28591 directly to UTF-8? appeared first on The Old New Thing.

via The Old New Thing

Swimming in July

Just the pure physical joy of thrashing your arms around in water. To fill the kid’s buckets and throw it at the sun—the way the water falls apart into drops, and then into mist, the way a rainbow appears for a second and is gone.

via Henrik Karlsson