zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    jquery获取元素各种宽高及页面宽高
    Mysql 多表联合查询效率分析及优化
    mysql连表操作是先连表还是先查询条件
    CSS实现垂直居中
    laravel中orderBy使用
    Spring官网改版后下载
    java.lang.NoClassDefFoundError: org/jaxen/JaxenException
    flex 简单跑马灯效果(竖着显示)
    Flex “跑马灯”效果(自定义“跑马灯”控件)
    当LinkButton无效时,光标不显示为手型
  • 原文地址:https://www.cnblogs.com/zy09/p/15683427.html
Copyright © 2011-2022 走看看