Skip to content

base64 encoding does not pad output properly #2

Closed
@shader

Description

@shader

Many base64 decoding libraries expect the encoded string to be padded with one or two "=" characters so that the length is a multiple of 4, as given by the following sample code in https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-08#appendix-C

static byte [] base64urldecode(string arg)
{
  string s = arg;
  s = s.Replace('-', '+'); // 62nd char of encoding
  s = s.Replace('_', '/'); // 63rd char of encoding
  switch (s.Length % 4) // Pad with trailing '='s
  {
    case 0: break; // No pad chars in this case
    case 2: s += "=="; break; // Two pad chars
    case 3: s += "="; break; // One pad char
    default: throw new System.Exception(
      "Illegal base64url string!");
  }
  return Convert.FromBase64String(s); // Standard base64 decoder
}

Can we have an option for byte-transforms/encode :base64 to include this padding?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions