How to encode a Map as Base64 string?

后端 未结 3 942
面向向阳花
面向向阳花 2020-12-16 23:57

i like to encode a java map of strings as a single base 64 encoded string. The encoded string will be transmitted to a remote endpoint and maybe manipulated by a not nice pe

3条回答
  •  独厮守ぢ
    2020-12-17 00:12

    Another possible way would be using JSON which is a very ligthweight lib. The the encoding then would look like this:

    JSONObject jso = new JSONObject( map );
    String encoded = new String(Base64.encodeBase64( jso.toString( 4 ).toByteArray()));
    

提交回复
热议问题