模塊描述:
該模塊提供一系列加密函數:算法
數據類型:安全
key_value() = integer() | binary()
digest_type() = md5 | sha | sha224 | sha256 | sha384 | sha512
hash_algorithms() = md5 | ripemd160 | sha | sha224 | sha256 | sha384 | sha512
rsa_private() = [key_value()] = [E, N, D] | [E, N, D, P1, P2, E1, E2, C]
dss_private() = [key_value()] = [P, Q, G, X]
ecdh_private() = key_value()
ecdh_params() = ec_named_curve() | ec_explicit_curve()
ec_named_curve() ->
sect571r1| sect571k1| sect409r1| sect409k1| secp521r1| secp384r1| secp224r1| secp224k1|
secp192k1| secp160r2| secp128r2| secp128r1| sect233r1| sect233k1| sect193r2| sect193r1|
sect131r2| sect131r1| sect283r1| sect283k1| sect163r2| secp256k1| secp160k1| secp160r1|
secp112r2| secp112r1| sect113r2| sect113r1| sect239k1| sect163r1| sect163k1| secp256r1|
secp192r1|
brainpoolP160r1| brainpoolP160t1| brainpoolP192r1| brainpoolP192t1| brainpoolP224r1|
brainpoolP224t1| brainpoolP256r1| brainpoolP256t1| brainpoolP320r1| brainpoolP320t1|
brainpoolP384r1| brainpoolP384t1| brainpoolP512r1| brainpoolP512t1
ec_explicit_curve() = {ec_field(), Prime :: key_value(), Point :: key_value(), Order :: integer(), CoFactor :: none | integer()}
ec_field() = {prime_field, Prime :: integer()} | {characteristic_two_field, M :: integer(), Basis :: ec_basis()}
ec_basis() = {tpbasis, K :: non_neg_integer()} | {ppbasis, K1 :: non_neg_integer(), K2 :: non_neg_integer(), K3 :: non_neg_integer()} | onbasis函數
經常使用函數:
sign/4
用法:加密
sign(Algorithm, DigestType, Msg, Key) -> binary() when Algorithm = rsa | dss | ecdsa, DigestType = digest_type(), Msg = binary() | {digest, binary()}, Key = rsa_private() | dss_private() | [ecdh_private(), ecdh_params()].
生成數字簽名,相似於public_key:sign/3。spa
verify/5code
verify(Algorithm, DigestType, Msg, Signature, Key) -> boolean() when Algorithm = rsa | dss | ecdsa, DigestType = digest_type(), Msg = binary() | {digest,binary()}, Signature = binary(), Key = rsa_public() | dss_public() | [ecdh_public(),ecdh_params()].
數字簽名驗證,相似於public_key:verify/4。blog
hmac/3 & hmac/4ip
hmac(Type, Key, Data, MacLength) -> binary() when Type = 散列算法,除了ripemd160, Key = iodata(), Data = iodata(), MacLength = integer().
利用哈希算法,一個密鑰Key和一個消息Data爲輸入,生成一個消息摘要。md5