開発および申請プロセス中、クライアントとサーバーは多くの場合、データを送信する必要があります。重要な個人情報が関与している場合、開発者は当然それを暗号化することを考えます。送信プロセス中に「マインドフルの人々」によって傍受されたとしても、情報は漏れません。多くの開発者は、MD5暗号化、Base64暗号化、DES暗号化、AES暗号化、RSA暗号化などの暗号化アルゴリズムを聞いたことがあると思います。単純な暗号化は、OR、およびなどを使用して実行できます。
サンプルコードで使用される ^操作キー= 0x01は、独自のルールをカスタマイズできます。独自の操作を定義して、可逆データが失われないようにします。キーを定義することもできます、動的キー。
Javaコード
public static string myencode(string str)throws unsupportedencodingexception {byte [] strbytes = str.getBytes( "utf-8"); byte [] newtrbyte = new byte [strbytes.length]; for(int i = 0; i <strbytes.length; i ++){newtrbyte [i] =(byte)(strbytes [i] ^ 0x01); } new String(NewStrbyte)を返します。 } string encodestr = myEncode( "idmmna/" 547 ''+) ')JavaScriptコード
UTF-8のバイトを取得します
function toutf8array(str){var utf8 = []; for(var i = 0; i <str.length; i ++){var charcode = str.charcodeat(i); if(charcode <0x80)utf8.push(charcode); else if(charcode <0x800){utf8.push(0xc0 |(charcode >> 6)、0x80 |(charcode&0x3f)); } else if(charcode <0xd800 || charcode> = 0xe000){utf8.push(0xe0 |(charcode >> 6)、0x80 |(charcode&0x3f)); } else if(charcode <0xd800 || charcode> = 0xe000){utf8.push(0xe0 |(charcode >> 12)、0x80 |((charcode >> 6)&0x3f)、0x80 |(charcode&0x3f)); } // surrogateペアelse {i ++; // UTF-16は0x10000-0x10ffffを// 0x10000を差し引き、0x0-0xffffffの20ビットを2つの半分に分割し、charcode = 0x10000 +(((charcode&0x3ff)<< 10)|(str.charcodeat(i)&0x3ff))); utf8.push(0xf0 |(charcode >> 18)、0x80 |((charcode >> 12)&0x3f)、0x80 |((charcode >> 6)&0x3f)、0x80 |(charcode&0x3f)); }} utf8を返します。 }バイトを取得して ^計算を実行します
bytes = stringtoasciibytearray(str); for(var i = 0; i <bytes.length; i ++){var newbyte =(bytes [i]^0x01); // newByte =(newByte^0x01); console.log(String.FromCharcode(newByte)); encodestr += string.fromCharcode(newByte); }; console.log(encodestr);要約します
上記は、Java&JavaScriptカスタム暗号化されたデータ送信コードの例に関するこの記事の全体的な内容です。すべての人に役立つことを願っています。興味のある友達は引き続きこのサイトを参照できます:
Java Exploration:スレッド+IOファイルの暗号化および復号化コードの例
マルチモード文字列マッチングアルゴリズムの原則とJava実装コード
赤と黒の木を実装するためのJavaアルゴリズムの完全なコード例
欠点がある場合は、それを指摘するためにメッセージを残してください。