jsencrypt.js RSA(非对称加密)浏览器js插件

jsencrypt.js RSA(非对称加密)浏览器js插件

jsencrypt.js RSA(非对称加密)浏览器js插件

使用方式:

第一步加载bfwone

第二步use插件

第三步执行插件的方法

示例如下

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>BFW NEW PAGE</title>
    <script id="bfwone" data="dep=jquery.17&err=0" type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/bfwone.js"></script>
    <script type="text/javascript">
        bready(function() {
            use(["jsencrypt"], function() {
                // Run a quick encryption/decryption when they click.
                $('#testme').click(function() {

                    // Encrypt with the public key...
                    var encrypt = new JSEncrypt();
                    encrypt.setPublicKey($('#pubkey').val());//设置公钥
                    var encrypted = encrypt.encrypt($('#input').val());//加密

                    // Decrypt with the private key...
                    var decrypt = new JSEncrypt();
                    decrypt.setPrivateKey($('#privkey').val());//设置私钥
                    var uncrypted = decrypt.decrypt(encrypted);//解密

                    // Now a simple check to see if the round-trip worked.
                    if (uncrypted == $('#input').val()) {
                        alert('加密解密成功');
                    } else {
                        alert('出错了');
                    }
                });
            });
        });
    </script>
</head>
<body>
    <label for="privkey">私钥</label><br />
    <textarea id="privkey" rows="15" cols="65">-----BEGIN RSA PRIVATE KEY-----
        MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ
        WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR
        aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB
        AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv
        xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH
        m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd
        8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF
        z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5
        rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM
        V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe
        aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil
        psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz
        uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876
        -----END RSA PRIVATE KEY-----</textarea><br />
    <label for="pubkey">公钥</label><br />
    <textarea id="pubkey" rows="15" cols="65">-----BEGIN PUBLIC KEY-----
        MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN
        FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76
        xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4
        gwQco1KRMDSmXSMkDwIDAQAB
        -----END PUBLIC KEY-----</textarea><br />
    <label for="input">待加密字符串:</label><br />
    <textarea id="input" name="input" type="text" rows=4 cols=70>This is a test!</textarea><br />
    <input id="testme" type="button" value="测试一下" /><br />
</body>
</html>

官网 https://github.com/travist/jsencrypt
立即下载jsencrypt.js查看所有js插件

网友评论0

程序员在线工具箱