From e55e3b6f5a9f14e2971769d3a619eaec878c2e89 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Tue, 1 Nov 2016 12:22:42 -0700 Subject: [PATCH] Updated Authentication's Base64UrlTextEncoder to use WebUtilities's Base64UrlTextEncoder logic --- .../DataHandler/TextEncoder.cs | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNetCore.Authentication/DataHandler/TextEncoder.cs b/src/Microsoft.AspNetCore.Authentication/DataHandler/TextEncoder.cs index c07a314b05..c0663295cf 100644 --- a/src/Microsoft.AspNetCore.Authentication/DataHandler/TextEncoder.cs +++ b/src/Microsoft.AspNetCore.Authentication/DataHandler/TextEncoder.cs @@ -1,31 +1,30 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; - namespace Microsoft.AspNetCore.Authentication { public static class Base64UrlTextEncoder { + /// + /// Encodes supplied data into Base64 and replaces any URL encodable characters into non-URL encodable + /// characters. + /// + /// Data to be encoded. + /// Base64 encoded string modified with non-URL encodable characters public static string Encode(byte[] data) { - return Convert.ToBase64String(data).TrimEnd('=').Replace('+', '-').Replace('/', '_'); + return WebUtilities.Base64UrlTextEncoder.Encode(data); } + /// + /// Decodes supplied string by replacing the non-URL encodable characters with URL encodable characters and + /// then decodes the Base64 string. + /// + /// The string to be decoded. + /// The decoded data. public static byte[] Decode(string text) { - return Convert.FromBase64String(Pad(text.Replace('-', '+').Replace('_', '/'))); + return WebUtilities.Base64UrlTextEncoder.Decode(text); } - - private static string Pad(string text) - { - var padding = 3 - ((text.Length + 3) % 4); - if (padding == 0) - { - return text; - } - return text + new string('=', padding); - } - } }