【发布时间】:2019-12-25 21:03:42
【问题描述】:
我需要使用 API,但首先我需要创建签名。
1. Concatenate the API key with the current timestamp in the format below:
<<APIKEY>>_<<timestamp(yyyy'-'MM'-'ddTHH:mm:ss.fffZ)>>
这一步很简单:
hash('sha256', $data);
结果是: 9952375a30708b46739986482303cae30ad51fc9a362b5794d298dfc22f7ec02 这是正确的结果
下一步是:
2. The combination of the created signature along with the provided API secret key will act as the
digital signature of the call.
我有 API 密钥,例如:
-----BEGIN PUBLIC KEY-----
9IGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCgBSU90PX4WyXFAZ/+M84dJNEi
/0j5OermfydTU4g2JvnpO6BOQjNpb5+mOLjVoij7DWTdDtx1WThRm04N3DVuyh+a
5cledvMbcngvyiXpQCdskT9bVmI4QLbmRny46S7MER1jhziMQRfRw9gbmlB2iCEq
n21kDr842Q+WDtLE4QIDAQA9
-----END PUBLIC KEY-----
如何通过创建的签名和提供的 API 密钥的组合获得数字签名?
有一个 Python 示例,如:
key = api_key + '_' + timestamp
print "message", key
sha_hash = hashlib.sha256(key).hexdigest()
print "sha256 hash:", sha_hash
rsa_key = RSA.importKey(pub_key)
cipher = PKCS1_v1_5.new(rsa_key)
signature = base64.encodestring(cipher.encrypt(sha_hash))
但是如何使用 PHP 获取签名?
【问题讨论】:
-
不确定您使用的是什么平台,但查看了
openssl_encrypt? -
是的,我想我需要使用 openssl_encript
-
还有其他一些选项,但我认为 openssl 通常在大多数系统上维护。 FWIW:Simplest two-way encryption using PHP - 旧的,有些信息可能已经过时了。
-
@ficuscr 你能写一个答案吗?
标签: php rsa digital-signature sha256 public-key