码迷,mamicode.com
首页 > 编程语言 > 详细

Python进行RSA安装加密

时间:2017-10-01 00:30:56      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:return   href   int   install   csharp   scripts   拷贝   3.1.1   imp   

一、下载ez_setup.pyhttp://peak.telecommunity.com/dist/ez_setup.py

二、用python解释执行它 (如使用IDLE打开该py文件,按F5解释执行)

三、安装完成后,会在scripts文件夹下生成几个exe可执行文件。(如: D:\Python27\Scripts目录下)

四、可以把之前下载的文件rsa-3.1.1-py2.7.egg拷贝到D:\Python27\Scripts目录下, 然后在cmd中切换到D:\Python27\Scripts目录下,执行egg文件:easy_install.exe rsa-3.1.1-py2.7.egg

加密实例

import os
import sys
import math

def GetDataFromFile(filename):
    f = open(filename)
    n = int(f.read(),16)
    print(‘*‘*77)
    print(filename)
    print(hex(n))
    print(‘*‘*77)
    return (n)
    
def my_RSA_encrypt(src, d, n):
    x = pow(src, d, n)
    print(‘*‘*77)
    print("Encrypted Data is:")
    print(hex(x))
    print(‘*‘*77)
    return x
    
def my_RSA_decrypt(src, e, n):
    y = pow(src, e, n)
    print(‘*‘*77)
    print("Decrypted Data is:")
    print(hex(y))
    print(‘*‘*77)
    return y   
    
path = os.getcwd()
#====================================
fname = path + "\\Firm_N.txt"
plaintData = GetDataFromFile(fname)


fname = path + "\\Manuf_private_d.txt"
d = GetDataFromFile(fname)


fname = path + "\\Manuf_N.txt"
n = GetDataFromFile(fname)


encryptedData = my_RSA_encrypt(plaintData, d, n)
#====================================
fname = path + "\\Firm_public_e.txt"
plaintData = GetDataFromFile(fname)


fname = path + "\\Manuf_private_d.txt"
d = GetDataFromFile(fname)


fname = path + "\\Manuf_N.txt"
n = GetDataFromFile(fname)


encryptedData = my_RSA_encrypt(plaintData, d, n)
#====================================

  

 

Python进行RSA安装加密

标签:return   href   int   install   csharp   scripts   拷贝   3.1.1   imp   

原文地址:http://www.cnblogs.com/hyh123/p/7616422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!