Skip to content

Commit a4951b2

Browse files
committed
Fix hex for larger values
1 parent baaec2a commit a4951b2

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

ios/RCTCrypto/lib/Shared.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
@implementation Shared
88

99
+ (NSString *) toHex:(NSData *)nsdata {
10-
NSString * hexStr = [NSString stringWithFormat:@"%@", nsdata];
11-
for(NSString * toRemove in [NSArray arrayWithObjects:@"<", @">", @" ", nil])
12-
hexStr = [hexStr stringByReplacingOccurrencesOfString:toRemove withString:@""];
13-
return hexStr;
10+
// Copied from: https://riptutorial.com/ios/example/18979/converting-nsdata-to-hex-string
11+
const unsigned char *bytes = (const unsigned char *)nsdata.bytes;
12+
NSMutableString *hex = [NSMutableString new];
13+
for (NSInteger i = 0; i < nsdata.length; i++) {
14+
[hex appendFormat:@"%02x", bytes[i]];
15+
}
16+
return [hex copy];
1417
}
1518

1619
+ (NSData *) fromHex: (NSString *)string {

0 commit comments

Comments
 (0)