2
iOSはキー生成のためのAPIとECDHを使った秘密鍵の導出を公開していますか?楕円曲線Diffie Hellman in ios/swift
Appleはそれを内部的に(特にx25519)使用していますが、一般的な暗号やそれ以外の方法で公開APIとして公開されているわけではありません。
おかげで、
iOSはキー生成のためのAPIとECDHを使った秘密鍵の導出を公開していますか?楕円曲線Diffie Hellman in ios/swift
Appleはそれを内部的に(特にx25519)使用していますが、一般的な暗号やそれ以外の方法で公開APIとして公開されているわけではありません。
おかげで、
は、Xcodeの8.3.3と遊び場に完了
Zは、その後、アリスのプライベートとボブの公開を使用してアリスの共有秘密を計算し、アリス、ボブのためのECを使用して公開鍵/秘密鍵を生成し、ボブのプライベートとアリスの公開を使ってボブの秘密を共有し、最終的に彼らが平等であると主張する。
import Security
import UIKit
let attributes: [String: Any] =
[kSecAttrKeySizeInBits as String: 256,
kSecAttrKeyType as String: kSecAttrKeyTypeEC,
kSecPrivateKeyAttrs as String:
[kSecAttrIsPermanent as String: false]
]
var error: Unmanaged<CFError>?
if #available(iOS 10.0, *) {
// generate a key for alice
guard let privateKey1 = SecKeyCreateRandomKey(attributes as CFDictionary, &error) else {
throw error!.takeRetainedValue() as Error
}
let publicKey1 = SecKeyCopyPublicKey(privateKey1)
// generate a key for bob
guard let privateKey2 = SecKeyCreateRandomKey(attributes as CFDictionary, &error) else {
throw error!.takeRetainedValue() as Error
}
let publicKey2 = SecKeyCopyPublicKey(privateKey2)
let dict: [String: Any] = [:]
// alice is calculating the shared secret
guard let shared1 = SecKeyCopyKeyExchangeResult(privateKey1, SecKeyAlgorithm.ecdhKeyExchangeStandardX963SHA256, publicKey2!, dict as CFDictionary, &error) else {
throw error!.takeRetainedValue() as Error
}
// bob is calculating the shared secret
guard let shared2 = SecKeyCopyKeyExchangeResult(privateKey2, SecKeyAlgorithm.ecdhKeyExchangeStandardX963SHA256, publicKey1!, dict as CFDictionary, &error) else {
throw error!.takeRetainedValue() as Error
}
print(shared1==shared2)
} else {
// Fallback on earlier versions
print("unsupported")
}
ありがとう@Mats右direction..3で私を送信するため
あなたは 'SecKeyCopyKeyExchangeResult'を見ていたことがありますか? – Mats
@Matsありがとう - 私はやった、それは関連しているようだが、残念なことにドキュメンテーションはとても貧しく、それを使用する方法を伝えるのは難しいし、私がしたいことをしている場合は難解です。 –
'SecKey.h'ヘッダファイルには、オンラインドキュメントにないいくつかの追加情報があるかもしれません。 – Mats