Base64UtilsTest.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.maxkey.crypto;
  17. import org.junit.Test;
  18. public class Base64UtilsTest {
  19. /**
  20. * @param args
  21. */
  22. @Test
  23. public void test() {
  24. String encode=Base64Utils.encoder("base64ToFile".getBytes());
  25. System.out.println(encode);
  26. String decode=Base64Utils.decode(encode);
  27. System.out.println(decode);
  28. String urlEncode=Base64Utils.base64UrlEncode("{\"typ\":\"JWT\",\"alg\":\"HS256\"}".getBytes());
  29. System.out.println(urlEncode);
  30. String urlDecode=new String(Base64Utils.base64UrlDecode(urlEncode));
  31. System.out.println(urlDecode);
  32. System.out.println(Base64Utils.decode("AAMkADU2OWY1MGQ3LWEyNWQtNDFmOC04MWFiLTI5YTE2NGM5YTZmNABGAAAAAABPKgpqnlfYQ7BVC/BfH2XIBwCS0xhUjzMYSLVky9bw7LddAAAAjov5AACS0xhUjzMYSLVky9bw7LddAAADzoyxAAA="));
  33. String b = "UsWdAIe4opTqcrX6~SrIMhBu5Gc9oZKEnnSDFRx9JwBINK8XTgnXUs2A3b7QmxDM9nRu8~mGsikVEoISLg.JTIHYRwv-Bp5ljIADLwUHv9iJAWo1delBOlW0Hd7nIVF0";
  34. System.out.println(DigestUtils.digestBase64Url(b,DigestUtils.Algorithm.SHA256));
  35. }
  36. }