Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Haskell RSA crypto random generator type

My goal is to generate a keypair using generateKeyPair from Codec.Crypto.RSA.

This function requires a generator of type RandomGen. I have tried to make this generator with newGenIO, but I’m having a hard time specifying its type.

import qualified Codec.Crypto.RSA as Crypto
import Crypto.Random

someFunc = do
  let g = newGenIO :: CryptoRandomGen (IO SystemRandom)
  let keyPair = Crypto.generateKeyPair g 10

Haskell suggested CryptoRandomGen SystemRandom when I didn’t specify a type after newGenIO.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is the error message that comes when trying to run the code.

    • Expected a type, but
      ‘CryptoRandomGen (IO SystemRandom)’ has kind
      ‘Constraint’

Does anyone know what type I have use to get it to work?

>Solution :

Try replacing that line with this one:

  g <- newGenIO :: IO SystemRandom

When you want a specific instance of a class, you just use the type, rather than specifying the class again. And to get something out of IO, you need to bind into it rather than just using =.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading