mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 13:23:34 +00:00
Fix base64url decode on MacOS passkeys (#14227)
* Add support for padding in base64url decode * whitespace * whitespace
This commit is contained in:
@@ -18,9 +18,25 @@ NSString *serializeJson(NSDictionary *dictionary, NSError *error) {
|
||||
}
|
||||
|
||||
NSData *decodeBase64URL(NSString *base64URLString) {
|
||||
if (base64URLString.length == 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Replace URL-safe characters with standard base64 characters
|
||||
NSString *base64String = [base64URLString stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
|
||||
base64String = [base64String stringByReplacingOccurrencesOfString:@"_" withString:@"/"];
|
||||
|
||||
// Add padding if needed
|
||||
NSUInteger paddingLength = 4 - (base64String.length % 4);
|
||||
if (paddingLength < 4) {
|
||||
NSMutableString *paddedString = [NSMutableString stringWithString:base64String];
|
||||
for (NSUInteger i = 0; i < paddingLength; i++) {
|
||||
[paddedString appendString:@"="];
|
||||
}
|
||||
base64String = paddedString;
|
||||
}
|
||||
|
||||
// Decode the string
|
||||
NSData *nsdataFromBase64String = [[NSData alloc]
|
||||
initWithBase64EncodedString:base64String options:0];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user