🔑 Batteries-Included High-Level API for Application Programmers
If you have ever tried to implement basic cryptographic operations and yet you are a developer rather than a cryptography professional, things can become overwhelming very quickly. What algorithm(s) to use, what is safe enough, what is not safe, which implementation, padding, what type of key, encoding, and how many bits should the key size be? Rings a bell?
Having encountered these questions repeatedly, we decided to distill a high-level library with the most common cryptographic operations used ubiquitously today. We pursued creating a developer-friendly implementation like what pyca/cryptography
offers in the python
ecosystem, following best practices and recommendations from a wide array of literature. Enter schmuio/cryptography
:
Key points:
Cryptography is exceedingly complex so its mathematical implementation should be left to the very limited number of deep subject matter experts in algorithms’ low-level details and properties
Respectful of the above, we have selected implementations from the go/crypto package and the Google Cloud Platform key management and cryptography APIs to underpin our higher-level functions
Yet, an overwhelming majority of cryptography libraries like go/crypto and Google’s Tink whilst obviously being industry-standard can be still pretty confusing to get going from a perspective of an application developer (nothing wrong with these libraries, but seemingly they are just targeted in a bit different audience)
This complexity either brings risks for one to get things wrong or acts as a deterrent to applying cryptographic operations altogether
To bridge this gap, we offer a very easy-to-handle selection of the recommended algorithms for symmetric encryption, asymmetric encryption, digital signatures, and time-based one-time passwords
Symmetric Encryption:
schmuio/cryptography
offers two algorithms for symmetric encryption which considered the present industry standard — AES GCM and ChaCha20-Poly1305package yourpackage import (
"github.com/schmuio/cryptography"
)
yourKey, err := cryptography.Key256b()
// handle potential error ...
ciphertext, err := cryptography.EncryptAesGcm("some-important-plaintext", yourKey)
// handle potential error ...
plaintext, err := cryptography.DecryptAesGcm(ciphertext, yourKey)
// handle potential error ...
Keys, plaintext, and ciphertext are all in string format to prevent explicit dealing with type conversions, encodings, etc.
Key generation functions guarantee keys have the right bit sizes and are generated in a cryptographically sound way
Asymmetric Encryption:
package yourpackage
import (
"github.com/schmuio/cryptography"
)
privateKey, publicKey, err := cryptography.RsaKeyPairPem()
// handle potential error ...
ciphertext, err := cryptography.EncryptRsa("some-important-plaintext", publicKey)
// handle potential error ...
plaintext, err := cryptography.DecryptRsa(ciphertext, privateKey)
// handle potential error ...
Note: asymmetric encryption can be applied only to short plaintexts (e.g. up to a few hundred bits); if you want to encrypt larger data you might use hybrid encryption — a scheme where one uses symmetric encryption for the data and asymmetric encryption only to encrypt the symmetric key that encrypts the data
Digital Signatures:
package yourpackage
import (
"github.com/schmuio/cryptography"
)
privateKey, publicKey, err := cryptography.RsaKeyPairPem()
// handle potential error ...
signature, err := cryptography.SignRsaPss("some-very-important-message", privateKeyPem)
// handle potential error ...
err = cryptography.VerifyEcdsa("some-very-important-message", signature, publicKey)
// handle potential error ...
Note: messages of arbitrary size can be signed because the message text is hashed to a fixed-size string before signing
Thank you for reading. If you have found this useful, please give us a star on GitHub, request a feature, or share a recommendation.