Base64編碼位元組陣列

2021-06-02 13:48:08 字數 2093 閱讀 8395

/**

* base64編碼處理

* */

public final class base64

for (int i = 'z'; i >= 'a'; i--)

for (int i = 'z'; i >= 'a'; i--)

for (int i = '9'; i >= '0'; i--)

base64_alphabet['+'] = 62;

base64_alphabet['/'] = 63;

for (int i = 0; i <= 25; i++)

for (int i = 26, j = 0; i <= 51; i++, j++)

for (int i = 52, j = 0; i <= 61; i++, j++)

lookup_base64_alphabet[62] = (byte) '+';

lookup_base64_alphabet[63] = (byte) '/';

} /**

* return true if the specified octect is base64

* * @param octect

* the octet to test.

* @return boolean true if the octect is base64.

*/static boolean isbase64(byte octect)

/*** encodes hex octects into base64

* * @param binarydata

* array containing binarydata

* @return base64-encoded array

*/public static byte encode(byte binarydata) else

byte k = 0;

byte l = 0;

byte b1 = 0;

byte b2 = 0;

byte b3 = 0;

int encodedindex = 0;

int dataindex = 0;

int i = 0;

for (i = 0; i < numbertriplets; i++)

// form integral number of 6-bit groups

dataindex = i * 3;

encodedindex = i * 4;

if (fewerthan24bits == eightbit) else if (fewerthan24bits == sixteenbit)

return encodeddata;

} /**

* decodes base64 data into octects

* * @param base64data

* byte array containing base64 data

* @return array containing decoded data.

*/public static byte decode(byte base64data)

int numberquadruple = base64data.length / fourbyte;

byte decodeddata = null;

byte b1 = 0, b2 = 0, b3 = 0, b4 = 0, marker0 = 0, marker1 = 0;

int encodedindex = 0;

int dataindex = 0;

}decodeddata = new byte[lastdata - numberquadruple];

} for (int i = 0; i < numberquadruple; i++) else if (marker0 == pad) else if (marker1 == pad)

encodedindex += 3;

} return decodeddata;

}}

位元組陣列 base64, 流之間關係

1.字串轉換成位元組陣列 byte array encoding.utf8.getbytes 你好 2.位元組陣列轉換成base64字串 string base64 convert.tobase64string array 3.base64string轉換成位元組陣列 byte bitarray c...

字元位元組Base64編碼

上班之餘抽點時間出來寫寫博文,希望對新接觸的朋友有幫助。今天在這裡和大家一起學習一下字元位元組 base64碼編說明 base64碼編要求把3個8位位元組 3 8 24 轉化為4個6位的位元組 4 6 24 以後在6位的面前補兩個0,成形8位乙個位元組的式形。如果剩下的字元缺乏3個位元組,則用0填充...

base64編碼 動畫演示 Base 64 編碼

base64 是一種十分流行的編碼方式,僅僅使用 64 個字元加等號 就可以以文字的形式表示所有的二進位制資料了,因為它能夠把二進位制格式通過編碼轉換成可見字元,所有我們就可以通過的把二進位制格式比如,檔案等通過 base64 編碼然後通過文字的形式共享出去,是不是很神奇呀。把輸入的資料轉換成 二進...