Skip to content

Should change decode table to seamlessly decode URL Safe stuff.  #3

@tomandersen

Description

@tomandersen

http://commons.apache.org/codec/apidocs/src-html/org/apache/commons/codec/binary/Base64.html

You need to add a 62 and 63 once more to the decode table: (see above link)

// Note: '+' and '-' both decode to 62. '/' and '_' both decode to 63. This means decoder seamlessly handles both
//URL_SAFE and STANDARD base64. (The encoder, on the other hand, needs to know ahead of time what to emit).
//private static final byte[] DECODE_TABLE = {

For my purposes, I wanted full speed for encoding to URL_SAFE, so I added a new encode look up table, and then

static const char base64EncodingTable_URL_SAFE[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";

  • (NSString *)encodeBase64WithData_URL_SAFE:(NSData *)objData {
    return [self encodeBase64WithData:objData table:_base64EncodingTable_URL_SAFE];
    }
  • (NSString *)encodeBase64WithData:(NSData *)objData {
    return [self encodeBase64WithData:objData table:_base64EncodingTable];
    }

Tom

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions