Home - Rsa-Haskell - Postmodern-Postgres


RSA-Haskell is a collection of command-line cryptography tools and a cryptography library written in Haskell. It is intended to be useful to anyone who wants to secure files or communications or who wants to incorporate cryptography in their Haskell application.

On This Page:


rsa-haskell-2.0.1.zip. This file includes the command line tools for windows. This is intended for those who want to use cryptography on windows.

rsa-haskell-2.0.1.tar.gz. This file includes the source code for the command line tools and all the libraries. This is intended for those who want to use cryptography on UNIX platforms, incorporate the library into their Haskell project, or browse a Haskell project.

Using the command-line Tools

The command-line tools can be used to very quickly do common uses of cryptography. To start, extract the .zip packages in a directory and start a command prompt there.

Generate Keys. The most basic of commands is to generate cryptography keys. Do this by typing the following on a console.


This creates two files: public.key and private.key. You can share your public key with all your friends, but you should keep your private key to yourself to where only you can access it.

Encrypting a Message so Only Your Friend Can See It. To encrypt a message so only your friend can see it, you need to have his public key. Lets call that friend.public.key. Use the following command to encrypt the file message.txt.

ssencrypt friend.public.key message.txt

This creates the file message.txt.ss. Send this to as many people as you want, but only your friend can decrypt it!

Decrypting a Message. If your friend sent you a message that he encrypted with your public key, it is easy to decrypt it. Use the following commands to decrypt the file message.txt.ss with your private key.

ssdecrypt private.key message.txt.ss

This creates the file message.txt which is the decrypted version for your pleasure.

More Stuff... Encrypting and decrypting messages is just the basic stuff you might want to do with RSA-Haskell. You can use the sssign, and ssverify commands to prove to someone that you've seen a message. You can even encrypt a message with your private key and someone else's public key to prove to someone that you were the one who sent the message. There are many fun possibilities!

Incorporating Cryptography into your Application

The crypto library can be used at many different levels of complexity depending on how much control you would like over the resulting process. These libraries are licensed under the GPL which allows you to freely use this library for most open-source applications.

Module SS. SS provides the most basic set of functions to do encryption and decryption.

keygen :: IO ((Integer, Integer), (Integer, Integer))
encrypt :: (Integer, Integer) -> String -> IO String
decrypt :: (Integer, Integer) -> String -> String
sign :: (Integer, Integer) -> String -> IO String
verify :: (Integer, Integer) -> String -> String -> Bool

The above functions directly correspond to the programs above. The (Integer,Integer) tuple represents a key, whether it be public or private.

To see examples of the SS module, see the sskeygen.hs, ssencrypt.hs, ssdecrypt.hs, ssverify.hs, and sssign.hs files.

Modules RSA, EME_OAEP, EMSA_PSS, MGF, RSAES_OAEP, RSA_PSS, SHA1, and SHA512. These modules give the programmer access to the underlying cryptographical algorithms. A good amount of cryptographic knowledge is required to use these together, but using these gives you the most flexability.

Technical Details on Encryption

RSA-Haskell uses 2048 bit RSA public key cryptography as the core of its algorithms. The SHA512 hash algorithm is used in conjuction with OAEP for encrption and decryption formats. Similarly, the PSS uses SHA512 for signature creation and verification.