seckeyref

SecKeyCreateFromData fails on 10.9 with -2147415792

≡放荡痞女 提交于 2020-01-06 05:47:29
问题 I have a code that constructs an RSA public key on MacOS with the help of the security framework. This works fine on 10.11/10.12/10.13, but today I found that this fails on 10.9. Below is the constructor of the class that wraps the key: CRSAPublicKey(const unsigned char* pExponent, const std::size_t nExponentSize, const unsigned char* pModulus, const std::size_t nModulusSize) { static const SecAsn1Template kRsaPublicKeyTemplate[] = { { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(ASN1_RSA_PUBLIC_KEY) }

Seckey from public key string from server in Swift

大城市里の小女人 提交于 2019-12-21 05:10:27
问题 I want to encrypt data using RSA , I tried to generate the key in my code and it's working , But what I actually need is to get the public key as a string from server and then use it as Seckey so I can use it to encrypt data using RSA, I tried this code: //KeyString is the string of the key from server let KeyData = (keyString as NSString).dataUsingEncoding(NSUTF8StringEncoding) as NSData! var cert : Unmanaged<SecCertificateRef>!; var policy : Unmanaged<SecPolicy>!; cert =

Swift 3 export SecKey to String

家住魔仙堡 提交于 2019-12-20 14:38:06
问题 I am developing an iOS app using swift 3. I need to export an SecKey (which is the user RSA publickey reference) to a string (e.g base64) in order to share it through a generated QRCode. It also has to work the other way since the other user that scans the QRCode , will be able to rebuild a SecKey reference from the string extracted from the QRCode. I found few tutorials but I don't understand exactly what I need to extract from the SecKey reference, and I don't know how to convert it to a

CFRelease crash in iOS10

£可爱£侵袭症+ 提交于 2019-12-04 07:02:34
问题 Below is my code, which used to work fine till iOS 9. - (NSData *)encryptWithDataPublicKey:(NSString*)data keyTag:(NSString*)tag { SecKeyRef publicKey = NULL; NSData *publicTag = [NSData dataWithBytes:[tag UTF8String] length:[tag length]]; NSMutableDictionary *queryPublicKey = [[NSMutableDictionary alloc] init]; [queryPublicKey setObject:(__bridge id)kSecClassKey forKey:(__bridge id)kSecClass]; [queryPublicKey setObject:publicTag forKey:(__bridge id)kSecAttrApplicationTag]; [queryPublicKey

Seckey from public key string from server in Swift

爱⌒轻易说出口 提交于 2019-12-03 15:14:30
I want to encrypt data using RSA , I tried to generate the key in my code and it's working , But what I actually need is to get the public key as a string from server and then use it as Seckey so I can use it to encrypt data using RSA, I tried this code: //KeyString is the string of the key from server let KeyData = (keyString as NSString).dataUsingEncoding(NSUTF8StringEncoding) as NSData! var cert : Unmanaged<SecCertificateRef>!; var policy : Unmanaged<SecPolicy>!; cert = SecCertificateCreateWithData(kCFAllocatorDefault, KeyData); policy = SecPolicyCreateBasicX509(); var status : OSStatus =

CFRelease crash in iOS10

为君一笑 提交于 2019-12-02 10:41:00
Below is my code, which used to work fine till iOS 9. - (NSData *)encryptWithDataPublicKey:(NSString*)data keyTag:(NSString*)tag { SecKeyRef publicKey = NULL; NSData *publicTag = [NSData dataWithBytes:[tag UTF8String] length:[tag length]]; NSMutableDictionary *queryPublicKey = [[NSMutableDictionary alloc] init]; [queryPublicKey setObject:(__bridge id)kSecClassKey forKey:(__bridge id)kSecClass]; [queryPublicKey setObject:publicTag forKey:(__bridge id)kSecAttrApplicationTag]; [queryPublicKey setObject:(__bridge id)kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType]; [queryPublicKey setObject