I’m trying to use Crypto.Cipher.RSA, and I’m struggling with encryption and signing. I’ve looked at the hackage page.
How should I implement a round-trip example, with both the encrypt/decrypt and sign/verify processes?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your question worries me. Perhaps I am too familiar with Vincent’s work, but I feel that if you understand the operations then using the library would be straight forward or you would at least have very specific questions. Below, I walk through the two examples you requested and try to stop and explain for each item that might be a “curve ball”.
The packages we draw on are: cryptocipher (which you could have mentioned in your question), cprng-aes (for a secure random number generator), crypto-api (an interface to crypto routines, but we’ll limit ourselves to just the RNG interface), bytestring, and cryptohash (sign/verify operations are typically parameterizable by hash function).
Now lets encrypt and decrypt a string, then verify this is identity.
The crypto-api interface is used for random number generation. Because this is an overloaded function we explicitly specify the desired type of random number generator,
AESRNG.Generating the key requires the bit size (we used an rather low value for this demo, 512 bits) and any prime over two will do for generation, I just picked 3.
The result is as expected:
Signing is not much different, just get a RNG, generate keys, and when you sign be sure to specify the hash function and any meta data you would like to bind. I selected SHA256 (see the import above) and no metadata (
B.empty).The result is
Right True.I expect most users will make their own functions for some of these operations.
Some things I think Vincent and I can do to help people in the future (please suggest additions to this list):
Not everyone follows the haddock link from
CryptoRandomGento the crypto-api and those that do could probably use a pointer to thecprng-aesanddrbgpackages.Document all functions with examples (examples of poor documentation: The
Integervalue forgeneration? I read the source. The order of the twoByteStringvalues for verify? I guessed convention and read the source to confirm.)Provide a tutorial like this in Vincent’s module.