Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

base64url in java

https://web.archive.org/web/20110422225659/https://en.wikipedia.org/wiki/Base64#URL_applications

talks about base64Url - Decode


a modified Base64 for URL variant exists, where no padding '=' will be used, and the '+' and '/' characters of standard Base64 are respectively replaced by '-' and '_'


I created the following function:

public static String base64UrlDecode(String input) {     String result = null;     BASE64Decoder decoder = new BASE64Decoder();     try {         result = decoder.decodeBuffer(input.replace('-','+').replace('/','_')).toString();     }     catch (IOException e) {         System.out.println(e.getMessage());     }     return result; } 

it returns a very small set of characters that don't even resemble to the expected results. any ideas?

like image 399
ufk Avatar asked Apr 12 '11 20:04

ufk


People also ask

What is Base64URL?

base64url.com Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding. Each base64 digit represents exactly 6 bits of data.

What is Base64 encoding in Java?

What is Base64? Base64 is a binary-to-text encoding scheme that represents binary data in a printable ASCII string format by translating it into a radix-64 representation. Each Base64 digit represents exactly 6 bits of binary data.

What is Base64URL decode?

Base64URL Decode is a free online tool for decoding Base64URL values to original data. By default, it decodes Base64URL as plain text, nevertheless, it also supports binary data, such as images or other files.

What is import Java Util Base64?

You can encrypt and decrypt your data by using provided methods. You need to import java. util. Base64 in your source file to use its methods. This class provides three different encoders and decoders to encrypt information at each level.


1 Answers

Java8+

import java.util.Base64;   return Base64.getUrlEncoder().encodeToString(bytes); 
like image 89
Boris Treukhov Avatar answered Sep 30 '22 00:09

Boris Treukhov