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

Using iOS CryptoKit to generate key pairs not compatible with other platform

我尝试使用 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?)

您正在使用两条不同的曲线。您指定的 link 表明您正在尝试启动 secp256k1 密钥,但这与 CryptoKit P256 不同 - 这是曲线 secp256r1,请注意最后两个字符 k1 != r1。即使私钥实例化成功,public个密钥也会不同,所以签名验证(verification)总是会失败。

可以用secp256r1吗?它出现在您 link 访问的网站列表中,位于 sect571r1 上方。

一定要用secp256k1吗?如果是这样你可以使用

https://github.com/Sajjon/K1

以后想在 CryptoKit 中使用 secp256k1 吗?帮助我投票支持将其添加到 swift-crypto(CryptoKit 的开源变体)!