[Haskell-cafe] Codec.Crypto.RSA question

Charles-Pierre Astolfi cpa at crans.org
Fri Nov 19 17:53:49 EST 2010


Hi -cafe,

I have a question about Codec.Crypto.RSA: how to enforce that
(informally) decrypt . encrypt = id
Consider this code:

encrypt2 :: String -> ByteString
encrypt2 = fst . encrypt (mkStdGen n) pubKey encode
decrypt2 :: ByteString -> String
decrypt2 = toString . decrypt privKey

Since decrypt2 takes a bytestring which size is a multiple of the
modulus, I've guessed that the encrypted bytestring is padded with
'\NUL' characters.

But then some strange stuff shows up:

decrypt2 $ encrypt2 "haskell" returns "\NUL\NUL\NUL\NUL\EOThaskell"
decrypt2 $ encrypt2 "foobar" returns "\NUL\NUL\NUL\NUL\65533foobar"

I may use dropWhile to get rid of the NUL-padding, but can I assume
that I'll always get a random character between my string and the
padding?
I tried to pad myself with NUL characters but I got almost the same
results (the "random char" went to the head of the string)


--
Cp


More information about the Haskell-Cafe mailing list