Skip to content

Commit a826fd1

Browse files
committed
possible way to generate randomBytes
1 parent c64c052 commit a826fd1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m

+9-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#import "MXBase64Tools.h"
2626
#import "MXEncryptedSecretContent.h"
2727

28+
#import <Security/Security.h>
2829

2930
#pragma mark - Constants
3031

@@ -166,9 +167,14 @@ - (MXHTTPOperation*)createKeyWithKeyId:(nullable NSString*)keyId
166167
}
167168
else
168169
{
169-
OLMPkDecryption *decryption = [OLMPkDecryption new];
170-
[decryption generateKey:&error];
171-
privateKey = decryption.privateKey;
170+
uint8_t randomBytes[32];
171+
OSStatus status = SecRandomCopyBytes(kSecRandomDefault, sizeof(randomBytes), randomBytes);
172+
173+
if (status == errSecSuccess) {
174+
privateKey = [NSData dataWithBytes:randomBytes length:sizeof(randomBytes)];
175+
} else {
176+
MXLogDebug(@"Failed to generate random bytes with error: %d", (int)status);
177+
}
172178
}
173179

174180
if (error)

0 commit comments

Comments
 (0)