Skip to content

Commit

Permalink
possible way to generate randomBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Nov 14, 2024
1 parent c64c052 commit a826fd1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions MatrixSDK/Crypto/SecretStorage/MXSecretStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#import "MXBase64Tools.h"
#import "MXEncryptedSecretContent.h"

#import <Security/Security.h>

#pragma mark - Constants

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a826fd1

Please sign in to comment.