• python RSA 非对称加解密的实现


    import rsa
    # key = rsa.newkeys(3000)#生成随机秘钥
    # print(key)
    # privateKey = key[1]#私钥
    # publicKey = key[0]#公钥
    publicKey,privateKey = rsa.newkeys(512)
    
    print("---------------------publickey-----------------------------------")
    print(publicKey)
    print("--------------------private----------------------------")
    print(privateKey)
    
    print("----------------------------------------------------------------")
    message ='今天是个好天气.'
    print('Before encrypted:',message)
    message = message.encode('utf-8')
    cryptedMessage = rsa.encrypt(message, publicKey)
    print('After encrypted:\n',cryptedMessage)
    message = rsa.decrypt(cryptedMessage, privateKey)
    message = message.decode('utf-8')
    print('After decrypted:',message)
    ---------------------publickey-----------------------------------
    PublicKey(11094339865497149601310490665695900299972958166379734275537930367526372009879675274379008260629160161421109910257865963868050787526283952661277229965514083, 65537)
    --------------------private----------------------------
    PrivateKey(11094339865497149601310490665695900299972958166379734275537930367526372009879675274379008260629160161421109910257865963868050787526283952661277229965514083, 65537, 11013930151349246187046449237705520016431032916077914329844955148572574504182831044365625229604162692550100530623607085898959541854732989355203187180984401, 6550078916062476789721607999392441084050668611994634378761780693113499854022840279, 1693771938883205994040350937493672750899574358189149966944230739222619477)
    ----------------------------------------------------------------
    Before encrypted: 今天是个好天气.
    After encrypted:
     b'\xb00Gj\x07|#\x94\xd2^\xf3\x1a\x1e\xdcB"\xf1~W\x1c\xcf\xf0\x9c\n62\xea\xf0\xc9Q\x11\xe7\x92\x9aP\x93\xb9\xc5\x98\xba\xf6\x9fz\xa4\x972~)\xd1\xb5u\x95`\xc9p\x18QZS\xae\xd75\x02\x1a'
    After decrypted: 今天是个好天气.
    
    Process finished with exit code 0
  • 相关阅读:
    线上redis禁止使用keys等时间复杂度高的命令
    组合索引的使用效果的总结
    Netty 断线重连解决方案
    可作为GC Root的对象
    在同一个sqlSession执行一个相同的查询时,Mybatis有一级缓存,不会去查数据库,由此引发的一个bug
    HashMap 和 currentHashMap JDK8总结
    Java程序导致服务器CPU占用率过高的问题排除过程
    一条sql执行的很慢的原因有哪些
    主键索引和非主键索引的区别
    黑马程序员
  • 原文地址:https://www.cnblogs.com/zy09/p/15683427.html
Copyright © 2020-2023  润新知