【H5】两种加密解密方法:

【H5】两种加密解码方法:

encodeURI(); //加密
decodeURI(); //解密

加密成base64编码格式
btoa() 加密
atob() 解密

实现代码如下:


<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Documenttitle>
head>
<body>
    <script>
        // encodeURI 编码与 decodeURI 编码;
        const str = "帅德布耀布耀滴小雯老公";
        let strm = encodeURI( str )
        console.log( encodeURI( str ) )     //加密后就是str1
        const str1 = '%E5%B8%85%E5%BE%B7%E5%B8%83%E8%80%80%E5%B8%83%E8%80%80%E6%BB%B4%E5%B0%8F%E9%9B%AF%E8%80%81%E5%85%AC'
        console.log( decodeURI( str1 ) )    //解密后就是str

        //btoa 加密  atob 解密   base64编码格式
        const str2 = encodeURI("帅德布耀布耀滴小雯老公")
        console.log( str2 )
        
        const str3 = btoa( str2 );
        console.log( str3 )

        const str4 = atob( str3 );
        console.log( str4 )

        const str5 = decodeURI( str4 );
        console.log( str5 )
    script>
body>
html>

运行效果如下:

【H5】两种加密解密方法:_第1张图片

你可能感兴趣的:(HTML5,HTML5)