Abhishek Sharma
11/08/2024, 9:16 AMprivate fun getPublicKey(): SecKeyRef? {
val keyBase64 = BuildConfig.getEncryptionKey()
val decodeKey = NSData.create(keyBase64, 0u)
val keyRef = CFBridgingRetain(decodeKey) as CFDataRef
val attrib = NSDictionary.create(
mapOf(
kSecAttrKeyType to kSecAttrKeyTypeRSA,
kSecAttrKeyClass to kSecAttrKeyClassPublic
)
)
val attributeRef = CFBridgingRetain(attrib) as CFDictionaryRef
val error: CFErrorRef? = null
val errorRef = CFBridgingRetain(error) as CFErrorRefVar
val publicKey = SecKeyCreateWithData(keyRef, attributeRef, errorRef.ptr)
if(publicKey == null){
if(errorRef.value == null){
val errorDescription = CFErrorCopyDescription(errorRef.value)?.toString()
println("Error creating public key: ${errorDescription ?: "Unknown error"}")
}else {
println("Unknown error occurred while creating public key.")
}
}
return publicKey
}
public key is null. Any leads on what might be wrong here?Oleg Yukhnevich
11/08/2024, 11:04 AMAbhishek Sharma
11/08/2024, 11:14 AM