Base64加密解密

2021-05-22 16:29:08 字數 1103 閱讀 5751

public class base64

;//對應asicc字元的位置

public static string base64encode(string str)

c2 = str[i++];

if (i == len)

c3 = str[i++];

out += base64encodechars[c1 >> 2];

out += base64encodechars[((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4)];

out += base64encodechars[((c2 & 0xf) << 2) | ((c3 & 0xc0) >> 6)];

out += base64encodechars[c3 & 0x3f];

}return out;

}public static string utf16to8(string str)

else if (c > 0x07ff)

else

}return out;

}public static string base64decode(string str)

while (i < len && c1 == -1);

if (c1 == -1) break;

do while (i < len && c2 == -1);

if (c2 == -1) break;

out += (char)((c1 << 2) | ((c2 & 0x30) >> 4));

do while (i < len && c3 == -1);

if (c3 == -1) break;

out += (char)(((c2 & 0xf) << 4) | ((c3 & 0x3c) >> 2));

do while (i < len && c4 == -1);

if (c4 == -1) break;

out += (char)(((c3 & 0x03) << 6) | c4);

}return out;

}public static string utf8to16(string str)

}return out;}}

Base64 加密 解密

1 原理 轉碼過程例子 3 8 4 6 記憶體1個字元佔8位 轉前 s 1 3 先轉成ascii 對應 115 49 51 2進製 01110011 00110001 00110011 6個一組 4組 011100110011000100110011 然後才有後面的 011100 110011 00...

base64加密解密 java實現

base64是網路上最常見的用於傳輸8bit位元組碼的編碼方式之一,base64就是一種基於64個可列印字元來表示二進位制資料的方法。base64一般用於在http協議下傳輸二進位制資料,由於http協議是文字協議,所以在http協議下傳輸二進位制資料需要將二進位制資料轉換為字元資料。然而直接轉換是...

base64 的加密和解密

coding utf 8 如果報non ascii character xe6 in file odoo 123.py on line 5,but no encoding declared類似的這個錯加入這行就解決了 import base64 加密 defencryption str 想將字串轉編...