Java String Encode encodeString(String str)

Here you can find the source of encodeString(String str)

Description

Encode a string using Base64 encoding.

License

Apache License

Parameter

Parameter Description
str a parameter

Exception

Parameter Description
IOException an exception

Return

String

Declaration

public static String encodeString(String str) throws IOException 

Method Source Code

//package com.java2s;

import java.io.IOException;

import sun.misc.BASE64Encoder;

public class Main {
    /**// w ww .j a v a 2  s  . c o  m
     * Encode a string using Base64 encoding. Used when storing passwords
     * as cookies.
     *
     * This is weak encoding in that anyone can use the decodeString
     * routine to reverse the encoding.
     *
     * @param str
     * @return String
     * @throws IOException
     */
    public static String encodeString(String str) throws IOException {
        BASE64Encoder encoder = new BASE64Encoder();
        String encodedStr = encoder.encodeBuffer(str.getBytes());

        return (encodedStr.trim());
    }
}

Related

  1. encodeString(String s)
  2. encodeString(String s, boolean useUnicode)
  3. encodeString(String s, Integer size)
  4. encodeString(String s, String charset)
  5. encodeString(String sourceString, String sysCharset, String charset)
  6. encodeString(String strData)
  7. encodeString(String text, String charsetName)
  8. encodeString(String value)
  9. encodeStringByUTF8(String str)