Crypto library in Elixir, using Erlang public_key and OpenSSL ports
The package can be installed as:
- Add krypto to your list of dependencies in
mix.exs
:
def deps do
[{:krypto, "~> 0.1.4"}]
end
- Ensure krypto is started before your application:
def application do
[applications: [:krypto]]
end
Krypto is an opinionated, light-weight crypto implementation for Elixir with native OpenSSL bindings.
You can use krypto in your Elixir application to do the following:
- Generate an RSA key pair (in DER format):
{ publicKey, privateKey } = Krypto.RSA.getKeypair()
- Encrypt using the public key:
encrypted_secret = Krypto.RSA.encrypt("Super secret message", publicKey)
- Decrypt using the private key:
decrypted_secret = Krypto.RSA.decrypt(encrypted_secret, privateKey)
- Sign a message:
message = "This message should be signed",
signature = Krypto.RSA.sign(message, privateKey)
if Krypto.RSA.verify(message, signatre, publicKey) do
IO.puts "This signature matches!"
end
- Get message digests:
hash_md5 = Krypto.Hash.md5("Hash me in md5!")
hash_sha224 = Krypto.Hash.sha224("Hash me in sha224!")
hash_sha256 = Krypto.Hash.sha256("Hash me in sha256 (our prefered one)!")
hash_sha384 = Krypto.Hash.sha384("Hash me in sha384!")