程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在 Python 中使用 RSA 私钥加密数据?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何在 Python 中使用 RSA 私钥加密数据??

开发过程中遇到如何在 Python 中使用 RSA 私钥加密数据?的问题如何解决?下面主要结合日常开发的经验,给出你关于如何在 Python 中使用 RSA 私钥加密数据?的解决方法建议,希望对你解决如何在 Python 中使用 RSA 私钥加密数据?有所启发或帮助;

注意:我在 Python2.7 上使用 VisualStudio 来执行我的加密操作。

Q1:我想要做的操作是让程序根据从PublicKey收到的密文来检查和解密privateKey公式。

Q2: 在文档中,它描述了需要一种算法来计算明文代码。但是,文档没有具体说明如何根据模数计算该方程。我想弄清楚如何为我的 RSAFunction 编写一个 privateKeyCheck,所以一旦它运行了公钥,它就会验证密文。

RSA_Functions.py

class RSA:
def isPrime(n):

    # Corner case
    if (n <= 1):
        return False

    # Check from 2 to n-1
    for i in range(2,n):
        if (n % i == 0):
            return False

    return True

def modulus(p,q):
    return p * q

def eulerTotIEnt(p,q):
    return (p - 1) * (q - 1)

def findFactors(x):
    factorList = []
    for i in range(1,x + 1):
        if x % i == 0:
            factorList.append(i)
    return factorList

def publicKeyCheck(pList,qList,keyList):
    for i in keyList:
        if i in pList and i != 1:
            print('invalID public key')

        elif i in qList and i != 1:
            print('invalID public key')
        else:
            print(' public key is valID')
            break

正如您在上面看到的,对于方程,我们创建了两个质数 (pq) 来比较 eulertotIEnt 和公钥的因子,以确保它们与 EurlertotIEnt 没有公因子,并创建了一个 PublicKeyCheck 以查看是否它与 RSA 匹配。

from RSAFunctions import RSA

print('Welcome to the RSA Algorithm Simulator.')
print('First you will need to select two Prime numbers.')

#step one generate two prime numbers
p = int(input('\nEnter a prime number(p) : '))
q = int(input('Enter a prime number(q) : '))

print("\nChecking to see if inputs are valID: ")
print(RSA.isPrime(p))
print(RSA.isPrime(q))

print("\nNow printing the Modulus:")
print(RSA.modulus(p,q))

print("\nNow printing the eulerTotIEnt:")
print(RSA.eulerTotIEnt(p,q))

publicKey = int(
    input(
        "\nPlease Enter a small two digit number that has no 
common factors with the eulertotIEnt: "
    ))

factorseuler = RSA.findFactors(RSA.eulerTotIEnt(p,q))
factorsKey = RSA.findFactors(publicKey)

print('\nVeryifying public Key:')

RSA.publicKeyCheck(factorsKey)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的如何在 Python 中使用 RSA 私钥加密数据?全部内容,希望文章能够帮你解决如何在 Python 中使用 RSA 私钥加密数据?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: