参考apple 官网的文档:Applepay解密过程
原始数据Base64解码这里以RSA作为介绍,源码里面包含了Ecc的,文章不重复写
{
"version": "RSA_v1",
"data": "N6h9l7hs9bUn1DGfc9MEEhP9/COm5AVsIuzKSXMcG85P7FkR058VuQnYRCY+EiTx3Kde7EUfrCnHWeGurDEB5v5au0Omo8uLyKAMsFeEJYntgLw8Wnhf98UlrlT06UwqI16Y+iNu62EE1Uz2ydZJfyrBT7OpuCdK5LH2FIEsjElZrMh7NDofOz4vSErya/llAFSceZCJr09zVwBpz86AYspmXtnk098bF+93Dnw3bWH4X5L2FujP5OnGO4mKW5RxMDudm+t6tFKbHfESGJufAevFU5LSNGIYCunDxF7EAw/yDFUlLJBrEYL2ZSRPaV/SQ7WXvYqhg6WNm/ZMgJCW4apQ+JuqULMYTksxKQS6x/z5vdslk4803ByeeEOxEQK0QZ8o0QeOELnOJuNs",
"signature": "MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwEAAKCAMIIErTCCBFOgAwIBAgIISaWX1yvjfKIwCgYIKoZIzj0EAwIwejEuMCwGA1UEAwwlQXBwbGUgQXBwbGljYXRpb24gSW50ZWdyYXRpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTMB4XDTE2MDExMTIxMDEyM1oXDTIxMDEwOTIxMDEyM1owXzElMCMGA1UEAwwccnNhLXNtcC1icm9rZXItc2lnbl9VQzQtUFJPRDEUMBIGA1UECwwLaU9TIFN5c3RlbXMxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkQVz1Fhm2yl8s1VuXKa+oUqNn4I0f7cO3syJRN7u7E2QYSa/ZLrN5S/oT62zpPDtxKAIcTr1PbofjhZCCj2cSeyxwFG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Rit+PmzdzMpnYcl6u0ikozgEcepFhzIeNKIhjMRRE5xh40pPRlAOJeFUVBrnI55h9KXG4cZIeg0aBon0SFTo7aiIhNdSxZgEEZEnrR9bC8dJK4RoFbfNmvOHz9jTPE4EbbIL0dRP8TlOtrnA7gXf240zY0MxoNSE9mjDe1CFpSiseKgG1keZNN3cmhNpw=="
}
}
签名校验
如何保证数据是从applepay正确的来源,防止假冒数据。
虽然你不校验,发送到发卡行也会被校验出来错误的数据,但是,在银行交易里面,简单的错误多了,轻则会被卡组织罚款,重则被取消支付牌照。
获取对应秘钥这里值得说一下的是,在我们配置秘钥时我们如何计算这个Hash,从而,让我们真正拿到hash时,能够通过hash来获取对应的秘钥,这部分代码资料比较少,很多人都是忽略这部分,直接自己定义了一套索引:
func CalcCerHash(cerContent []byte) (string, error) {
cer, err := x509.ParseCertificate(cerContent)
if err != nil {
return "", nil
}
ret := algorithmutils.Sha256(cer.RawSubjectPublicKeyInfo)
return ret, nil
}
未完待续。。。