Base64 encoding in Java / Groovy

前端 未结 5 1499
太阳男子
太阳男子 2020-12-14 16:27

What is the proper way to convert a byte [] to a Base64 string in Java? Better yet would be Grails / Groovy because it tells me that the encodeAsBase64() functi

5条回答
  •  眼角桃花
    2020-12-14 16:53

    The preferred way to do this in groovy is:

     def encoded = "Hello World".bytes.encodeBase64().toString()
     assert encoded == "SGVsbG8gV29ybGQ="
     def decoded = new String("SGVsbG8gV29ybGQ=".decodeBase64())
     assert decoded == "Hello World"
    

提交回复
热议问题