From a826fd1831c3f519301a8fe13512ccdf8ca22835 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Thu, 14 Nov 2024 17:40:51 +0100 Subject: [PATCH] possible way to generate randomBytes --- MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m b/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m index 3ffb6c6de..014c15215 100644 --- a/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m +++ b/MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m @@ -25,6 +25,7 @@ #import "MXBase64Tools.h" #import "MXEncryptedSecretContent.h" +#import #pragma mark - Constants @@ -166,9 +167,14 @@ - (MXHTTPOperation*)createKeyWithKeyId:(nullable NSString*)keyId } else { - OLMPkDecryption *decryption = [OLMPkDecryption new]; - [decryption generateKey:&error]; - privateKey = decryption.privateKey; + uint8_t randomBytes[32]; + OSStatus status = SecRandomCopyBytes(kSecRandomDefault, sizeof(randomBytes), randomBytes); + + if (status == errSecSuccess) { + privateKey = [NSData dataWithBytes:randomBytes length:sizeof(randomBytes)]; + } else { + MXLogDebug(@"Failed to generate random bytes with error: %d", (int)status); + } } if (error)