An open API service indexing awesome lists of open source software.

https://github.com/elefthei/krypto

OpenSSL and Erlang crypto bindings in Elixir, a crypto library with ease of use in mind
https://github.com/elefthei/krypto

crypto-library elixir krypto openssl

Last synced: 12 months ago
JSON representation

OpenSSL and Erlang crypto bindings in Elixir, a crypto library with ease of use in mind

Awesome Lists containing this project

README

          

# Krypto

**Crypto library in Elixir, using Erlang public_key and OpenSSL ports**

## Installation

The package can be installed as:

1. Add krypto to your list of dependencies in `mix.exs`:
```
def deps do
[{:krypto, "~> 0.1.4"}]
end
```
2. Ensure krypto is started before your application:
```
def application do
[applications: [:krypto]]
end
```
## Overview

Krypto is an opinionated, light-weight crypto implementation for Elixir with native OpenSSL bindings.

## Example

You can use krypto in your Elixir application to do the following:

1. Generate an RSA key pair (in DER format):
```
{ publicKey, privateKey } = Krypto.RSA.getKeypair()
```
2. Encrypt using the public key:
```
encrypted_secret = Krypto.RSA.encrypt("Super secret message", publicKey)
```
3. Decrypt using the private key:
```
decrypted_secret = Krypto.RSA.decrypt(encrypted_secret, privateKey)
```
4. 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
```
5. 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!")
```