1、问题描述
因业务要求,需要对指定的http请求内容进行RSA签名,并且将签名结果和请求内容用json格式打包。这里包括两个需要处理的点:1、用RSA私钥签名;2、把http请求json化。
2、处理签名
目前项目使用的erlang版本是17.0,这个版本有专门针对RSA的库即public_key,但是查看public_key相关描述
sign(Msg, DigestType, Key) -> binary()
Types:
Msg = binary() | {digest,binary()}
The msg is either the binary "plain text" data to be signed or it is the hashed value of "plain text" i.e. the digest.
DigestType = rsa_digest_type() | dss_digest_type() | ecdsa_digest_type()
Key = rsa_private_key() | dsa_private_key() | ec_private_key()
Creates a digital signature.
明显,参数需要rsa_private_key()类型参数,参数定义
-record('RSAPrivateKey',{
version, modulus, publicExponent, privateExponent, prime1, prime2, exponent1, exponent2, coefficient, otherPrimeInfos = asn1_NOVALUE}).
对于只有privatekey而没有生成key的两个素数的应用场景来说,这个库就是渣,感觉并没有什么卵用。其他方案?
1、http://blog.sina.com.cn/s/blog_48c0f7f10101bh7d.html
2、java和c++应该是有对应的库的,