3

Using Android's Base64, it's possible to do this: Base64.decode(privateKeyString, Base64.DEFAULT). If you are using Apache's Commons Codec, this isn't available. How can I achieve the same result using Commons Codec?

Sandah Aung
  • 6,156
  • 15
  • 56
  • 98

2 Answers2

4

Javadoc for Apache Commons Codec Base64 class can be found here: http://commons.apache.org/proper/commons-codec/archives/1.9/apidocs/org/apache/commons/codec/binary/Base64.html

For your case, you need to use Base64.decodeBase64(String base64String) method

Alexander Tokarev
  • 2,743
  • 2
  • 20
  • 21
  • I know that Android's 'Base64.DEFAULT' causes operation to use line terminators. Does 'Base64.decodeBase64(String base64String)' use line terminators as well? – Sandah Aung Jan 20 '14 at 05:36
  • 1
    Line terminators make sense on encoding data to base64. If you want your base64 encoded string to be divided on standard 76 characters chunks - use method `encodeBase64(byte[] binaryData, boolean isChunked)` with `isChunked=true`. However, line terminators don't impact on decoding, they're simply ignored. – Alexander Tokarev Jan 20 '14 at 05:44
  • Thanks a lot. We have been worrying if line terminators would affect decoding since we are using two encoding libraries on the server and client side. Now we can let our worries go and focus our efforts on functional requirements. – Sandah Aung Jan 20 '14 at 06:17
0

delete the base64 string head.for example,"data:image/png;base64,iVBORw0....",delete the string "data:image/png;base64,".then.it work well. i did it

perry
  • 856
  • 1
  • 10
  • 22