Base64 encoder and decoder

后端 未结 5 1731
感动是毒
感动是毒 2020-11-27 04:40

Is there a base-64 decoder and encoder for a String in Android?

5条回答
  •  情深已故
    2020-11-27 05:05

    Here is a simple method I was going to use until I realized that this is only supported in Android API 8+:

    // Has line break
    public String getBase64(String input) {
        return Base64.encodeToString(input.getBytes(), Base64.DEFAULT);
    }
    
    // No line break
    public String getBase64(String input) {
        return Base64.encodeToString(input.getBytes(), Base64.NO_WRAP);
    }
    

提交回复
热议问题