magic.lambda.crypto
The magic.lambda.crypto project provides cryptography helper slots for Magic, allowing you to use both symmetric and asymmetric cryptography operations in your Hyperlambda applications. The symmetric parts of the project is using AES internally, and the asymmetric parts is using RSA. In addition to a bunch of “low level slots”, the project also contains combination slots, combining RSA and AES, allowing you to both encrypt and sign a message, using a single signal invocation. This project also allows you to create RSA key pairs, in addition to cryptographically hashing files and payloads, etc. More specifically this project contains the following slots.
- [crypto.rsa.create-key] - Creates a new RSA keypair
- [crypto.rsa.encrypt] - RSA encrypts a message
- [crypto.rsa.decrypt] - RSA decrypts a message
- [crypto.rsa.sign] - Cryptographically signs a message
- [crypto.rsa.verify] - Verifies a cryptographic signature of some message
- [crypto.aes.encrypt] - AES encrypts a message
- [crypto.aes.decrypt] - AES decrypts a message
- [crypto.fingerprint] - Creates a fingerprint of something
- [crypto.get-key] - Returns the fingerprint of the public key associated with message
- [crypto.random] - CSRNG creating random seeds for you
- [crypto.random.int] - CSRNG creating random integer value for you
- [crypto.hash] - Hash some message or payload using the specified [algo] or [algorithm]
- [crypto.hash.md5] - MD5 hash some message or payload
- [crypto.hash.sha1] - SHA1 hash some message or payload
- [crypto.hash.sha256] - SHA256 hash some message or payload
- [crypto.hash.sha384] - SHA384 hash some message or payload
- [crypto.hash.sha512] - SHA512 hash some message or payload
- [crypto.password.hash] - Creates a Blowfish uniquely salted hash
- [crypto.password.verify] - Verifies a Blowfish uniquely salted hash
- [crypto.encrypt] - High level slot combining RSA and AES to encrypt some message
- [crypto.decrypt] - High level slot combining RSA and AES to decrypt some message
- [crypto.sign] - High level slot to sign some message
- [crypto.verify] - High level slot to verify a signature of some message
- [crypto.seed] - Allows you to explicitly seed the CSRNG instance using for instance a manually provided seed
Blowfish password hashing
As a general security rule of thumb, passwords should never be stored in clear text, but persisted into for instance a database as “slowly hashed values with per record based salts”. This prevents a whole range of security issues, such as having adversaries creating Rainbow Dictionary attacks on your passwords. This project contains two slots to implement this, and these are as follows.
- [crypto.password.hash] - Creates a password hash
- [crypto.password.verify] - Verifies a hashed password
Example usage can be found below.
crypto.password.hash:SomePasswordHere
crypto.password.verify:SomePasswordHere
hash:x:@crypto.password.hash
The first slot invocation creates a Blowfish hash, while the second slot invocation verifies a previously
created Blowfish hash, given the password as its main argument. If you exchange the second password given
to [crypto.password.verify] by for instance adding one random character to it, the result will be
false from the second invocation.
Internally these are the slots Magic uses when it creates its JWT authentication database, and stores
passswords into your Magic database.
Topics
- RSA cryptography with Hyperlambda - Creating RSA keypairs, signing and verifying the signature of a message, and encrypting and decrypting with RSA, using the cryptography slots of Hyperlambda.
- Symmetric cryptography using AES - Encrypting and decrypting a message with a shared secret using AES, with the cryptography slots of Hyperlambda.
- Hyperlambda and cryptography - The magic.lambda.crypto project supports several cryptographic functions, but first a bit of cryptography theory.
- Combining RSA and AES cryptography - AES and RSA are more useful when combined together.