rsa_keys
Simple and easy set of functions to generate rsa keys, sign a message and verify it, targeting erlang.
Funções simples e fáceis para gerar chaves rsa, assinar uma mensagem e verificála, usando erlang.
Types
representation of decrypting errors
pub type ErrorDecrypt {
Integrity
Format
}
Constructors
-
Integrity
-
Format
pub type PrivateKey {
PrivateKey(der: BitArray, pem: String)
}
Constructors
-
PrivateKey(der: BitArray, pem: String)
Functions
pub fn decode_pem_to_der(
pem_encoded_key key: String,
) -> Result(BitArray, String)
Decode a pem key to a der binary
pub fn decrypt_message(
message msg: BitArray,
private_key prvtkey: PrivateKey,
) -> Result(BitArray, ErrorDecrypt)
decrypt a message and it’s hash, compare the two and return it if valid.
pub fn encrypt_message(
message msg: BitArray,
pubkey pubkey: PublicKey,
) -> BitArray
encrypt a message and a hash attached to it’s end for proper validation later. the message can then be base 16 encoded for readability/storage.
pub fn generate_rsa_keys() -> #(PublicKey, PrivateKey)
Generate public and private RSA key pairs.
The pem records are PEM encoded and thus human readable.
pub fn sign_message(
message msg: BitArray,
private_key prvtkey: PrivateKey,
) -> Result(BitArray, String)
Hash a message using sha256 and sign it using a private key.
The returned signature can then be base16 encoded for readability.
pub fn sign_message_with_pem_string(
message msg: BitArray,
private_key_pem prvtkey_pem: String,
) -> Result(BitArray, String)
Same as sign_message but uses pem string as the argument.
pub fn verify_message(
message msg: BitArray,
public_key public_key: PublicKey,
signature signature: BitArray,
) -> Result(Bool, String)
verify a message against its sha256 hash and signature using a public key.
returns a Ok(True) for valid signature
returns a Ok(False) for invalid signature
returns an Error for runtime issues.
pub fn verify_message_with_pem_string(
message msg: BitArray,
public_key_pem_string public_key_pem: String,
signature signature: BitArray,
) -> Result(Bool, String)
Same as verify_message but with pem string as the argument.