我一直在尝试在 iOS 中为 secp224k1 曲线生成公钥和私钥。我们使用 ECDH 方法在移动端和后端之间进行 api 握手。在 Java 中,它是使用以下代码完成的。
public static KeyPair getECKeyPair() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
ECGenParameterSpec ecSpec = new ECGenParameterSpec("secp224k1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDH", "SC");
kpg.initialize(ecSpec);
return kpg.generateKeyPair();
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在 swift 中生成具有特定曲线(secp224k1)类型的密钥?我尝试使用苹果提供的 EC 算法通过以下代码进行握手。
//Generates public and private key with EC algorithm
public static func getKey() -> [String: SecKey]? {
let attributes: [String: Any] =
[kSecAttrKeySizeInBits as String: 256,
kSecAttrKeyType as String: kSecAttrKeyTypeEC,
kSecPrivateKeyAttrs as String:
[kSecAttrIsPermanent as String: false]
]
var error: Unmanaged<CFError>?
guard …Run Code Online (Sandbox Code Playgroud)