使用iOS CryptoKit生成与其他平台不兼容的密钥对



我试图用CryptoKit生成密钥对,但似乎密钥对与https://8gwifi.org/ecsignverify.jsp等其他平台不兼容

import CryptoKit
...
let privateKey = P256.Signing.PrivateKey()
let publicKey = privateKey.publicKey
//using this send this string to other platform
let publicKeyPem = publicKey.pemRepresentation
//keeping this one on my keychain
let privateKeyPem = privateKey.pemRepresentation
but this keypairs can't be verified in other platform, like when I sign some data with private key and can't be verified by someoneelse(but it works well on iOS platform, is there something I missed?)

您正在使用两个不同的曲线。您指定的链接显示您正在尝试初始化secp256k1密钥,但这与CryptoKit P256不同-这是曲线secp256r1,注意最后两个字符k1 != r1。即使私钥实例化成功,公钥也会不同,因此签名验证(验证)总是会失败。

你能用secp256r1吗?它存在于您链接到的站点的列表中,位于section 571r1之上。

你必须使用secp256k1吗?如果是,可以使用

https://github.com/Sajjon/K1

将来想在CryptoKit中使用secp256k1吗?帮我投票给我的建议,让它添加到swift-crypto (CryptoKit的开源变体)!

最新更新