| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Text; |
| | 6 | |
|
| | 7 | | namespace Azure.Security.KeyVault |
| | 8 | | { |
| | 9 | | internal static class Base64Url |
| | 10 | | { |
| | 11 | | public static byte[] Decode(string str) |
| | 12 | | { |
| 4 | 13 | | str = new StringBuilder(str).Replace('-', '+').Replace('_', '/').Append('=', (str.Length % 4 == 0) ? 0 : 4 - |
| | 14 | |
|
| 4 | 15 | | return Convert.FromBase64String(str); |
| | 16 | | } |
| | 17 | |
|
| | 18 | | public static string Encode(byte[] bytes) |
| | 19 | | { |
| 4 | 20 | | return new StringBuilder(Convert.ToBase64String(bytes)).Replace('+', '-').Replace('/', '_').Replace("=", "") |
| | 21 | | } |
| | 22 | |
|
| | 23 | | } |
| | 24 | | } |