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
- Host: GitHub
- URL: https://github.com/elefthei/krypto
- Owner: elefthei
- License: mit
- Created: 2016-07-17T02:37:58.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-08-23T20:29:49.000Z (almost 8 years ago)
- Last Synced: 2025-06-18T07:12:06.508Z (about 1 year ago)
- Topics: crypto-library, elixir, krypto, openssl
- Language: Elixir
- Size: 7.81 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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!")
```