• node启动js-3DES-ECB加密,python-3DES-ECB加密


    一.node启动js-3DES-ECB加密

    var arguments = process.argv.splice(2);
    // console.log('所传递的参数是:', arguments);
    
    var password = arguments[0];   //加密的password
    var t=  arguments[1];   //加密的txt
    var forge = require('node-forge');
    // var fs = require('fs'); 写文件
    // console.log(t);
    var n = forge.cipher.createCipher("3DES-ECB",password );
    n.start();
    n.update(forge.util.createBuffer(forge.util.encodeUtf8(t)));
    n.finish();
    var data = forge.util.encode64(n.output.getBytes()).toString();
    console.log(data);
    // fs.writeFile(name, data, function (error) {});
    

    二.python-3DES-ECB加密

    from Crypto.Cipher import DES3
    import base64
    import json
    BS = DES3.block_size
    
    
    def pad(s):
        return s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
    
    
    def unpad(s):
        return s[0:-ord(s[-1])]
    
    
    class prpcrypt():
        def __init__(self, key):
            self.key = key
            self.mode = DES3.MODE_ECB
    
        def encrypt(self, text):
            text = pad(text)
            cryptor = DES3.new(self.key, self.mode)
            x = len(text) % 8
            if x != 0:
                text = text + '' * (8 - x)
            text=text.encode("utf-8")
            self.ciphertext = cryptor.encrypt(text)
            return base64.standard_b64encode(self.ciphertext).decode("utf-8")
    
        def decrypt(self, text):
            cryptor = DES3.new(self.key, self.mode)
            de_text = base64.standard_b64decode(text)
            plain_text = cryptor.decrypt(de_text)
            st = str(plain_text.decode("utf-8")).rstrip('')
            out = unpad(st)
            return out
    
    code = json.dumps(text)  //加密的内容
    key = 'Q5yuGAZ2hHg1jhuRWjhc39oM'  //盐
    print(prpcrypt(key).encrypt(code))
    
  • 相关阅读:
    看MySQL官方文档的示例SQL有感
    MySQL 主外键约束与标准SQL不同的地方
    pip安装包时遇到的Bug
    MySQL update 语句与标准SQL不同的地方
    让MySQL在美国标准下运行
    mysqlslap 压力测试工具
    django 自动化测试的故障排查
    mysql-8.0.11 比较坑的地方dba门要淡定
    python3 如何给装饰器传递参数
    python3 装饰器应用举例
  • 原文地址:https://www.cnblogs.com/pythonywy/p/13220810.html
Copyright © 2020-2023  润新知