23

运行以下代码:

import Crypto.BCrypt
import Data.ByteString.Lazy.Char8

main = do
  maybe_pwhash <- hashPasswordUsingPolicy slowerBcryptHashingPolicy (pack "hunter2")
  print $ maybe_pwhash

我收到以下编译错误:

test.hs:5:70:
    Couldn't match expected type `Data.ByteString.Internal.ByteString'
                with actual type `ByteString'
    In the return type of a call of `pack'
    In the second argument of `hashPasswordUsingPolicy', namely
      `(C.pack "hunter2")'
    In a stmt of a 'do' block:
      maybe_pwhash <- hashPasswordUsingPolicy
                        slowerBcryptHashingPolicy (pack "hunter2")

我很困惑,因为我不明白为什么 aData.ByteString.Internal.ByteString和 a 之间有区别ByteString

4

1 回答 1

10

根据bcrypt 文档,您应该使用严格的字节串

import Data.ByteString.Char8

而不是懒惰的:

import Data.ByteString.Lazy.Char8
于 2013-12-22T20:47:54.740 回答