实现本地des和aes 解密的工具

举报
lxw1844912514 发表于 2022/03/27 02:31:41 2022/03/27
985 0 0
【摘要】 <?php$raw = file_get_contents('php://input');if(!empty($raw)) { parse_str($raw);//解析到当前作用域 if (!empty($method) && !empty($password) && !e...

        <?php
        $raw = file_get_contents('php://input');
        if(!empty($raw)) {
            parse_str($raw);//解析到当前作用域
           if (!empty($method) && !empty($password) && !empty($encodetext)) {
               $method = trim($method);
               $password = trim($password);
               $encodetext = trim($encodetext);
               $allowdmethod = ['aes', 'des'];
               if (!in_array($method, $allowdmethod)) {
                   die();
                }
               if ($method == 'aes') {
                   $method = 'aes-128-cbc';
                   $iv = '1234567890123456';
                }
               if ($method == 'des') {
                   $method = 'des-cbc';
                   $iv = '12345678';
                }
               $decodtext = openssl_decrypt($encodetext, $method, $password, false, $iv);
               die($decodtext);
            }
        }
        ?>
        <html>
            <head>
                <title>des和aes解密</title>
            </head>
            <body>
                <center>
                    <form action="#" method="">
                        <label for="">加密方式:</label>
                        <input type="radio" name="method" value="des">DES
                        <input type="radio" name="method" value="aes">AES<br/>
                        <label for="">密码:</label>
                        <input type="text" name="password" value=""><br/>
                        <label for="">密文:</label><br>
                        <textarea name="encodetext" id="" cols="100" rows="15"></textarea><br/>
                        <input style="width:100px;height:100px" type="submit" id="myform" value="解密">
                    </form>
                    <br><br>
                    <textarea id="decodetext" cols="100" rows="20">
                    </textarea>
                <center/>
                <script src="/static/js/jquery-1.8.3.min.js" type="text/javascript"></script>
                    <script type="text/javascript">
                       var myform = document.getElementById("myform");
                        myform.addEventListener('click',function(e){
                            e.preventDefault();
                           var method = $("input[name='method']:checked").val();
                           var password = $("input[name='password']").val();
                           var encodetext = $("textarea").val();
                           //console.log(method,password,encodetext);//return false;
                            $.ajax({
                                type : "POST",
                                url : "jsondecrypt.php",
                                data : {'method':method,'password':password,'encodetext':encodetext},
                                dataType : "text",
                                success : function(data){
                                    $("#decodetext").val(data);
                                   // console.log(data);
                                }
                            });
                        });
                    </script>
            </body>
        </html>
    
   

  

文章来源: blog.csdn.net,作者:lxw1844912514,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/lxw1844912514/article/details/100027774

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(0

抱歉,系统识别当前为高风险访问,暂不支持该操作

    全部回复

    上滑加载中

    设置昵称

    在此一键设置昵称,即可参与社区互动!

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。