WAS支持RSA公钥解密

需要将 -Dcom.ibm.crypto.provider.DoRSATypeChecking=false 

false改为true

 

详见:http://www-01.ibm.com/support/docview.wss?uid=swg1IV18625

 

APAR status

  • Closed as program error.

     

Error description

  • We have agreed to provide a flag for use at runtime to allow for
    the RSA encryption of data with the private key, as well as
    decryption of data with the public key.  This flag can be set
    with the following property:
    
    -Dcom.ibm.crypto.provider.DoRSATypeChecking=false
    
    In Java 5, 6, 6.0_26, and 7, the default value will be "true" --
    meaning that IBM's Java will have the old behavior.  If this
    flag is set to "false" IBM's Java will allow for the atypical
    scenario with the reversal of the keys described above.
    
    Please note: This configuration is not recommended for use by
    developers of standard applications.  It is understood that by
    setting this flag, a developer understands the behavior that is
    being enabled (encrypting with the private key/permitting anyone
    with the public key to decrypt).  In nearly all cases,
    performing a signature in the standard way (with the private key
    to sign and the public key to verify) is preferred and
    recommended.
    
    With this APAR we are making sure the PUBLIC KEY can be used for
    DECRYPT.
    

     

Local fix

  • N/A
    

     

Problem summary

  • ERROR DESCRIPTION:
    
    IBM JVM should support encrypting using the private key and
    decrypting using the public key
    
    Note: This is a follow-up to APAR IV17344, which allows the
    public key to decrypt properly in this configuration
    

     

Problem conclusion

  • We have agreed to provide a flag for use at runtime to allow for
    the RSA encryption of data with the private key, as well as
    decryption of data with the public key.  This flag can be set
    with the following property:
    
    -Dcom.ibm.crypto.provider.DoRSATypeChecking=false
    
    In Java 5, 6, 6.0_26, and 7, the default value will be "true" --
    meaning that IBM's Java will have the old behavior.  If this
    flag is set to "false" IBM's Java will allow for the atypical
    scenario with the reversal of the keys described above.
    
    Please note: This configuration is not recommended for use by
    developers of standard applications.  It is understood that by
    setting this flag, a developer understands the behavior that is
    being enabled (encrypting with the private key/permitting anyone
    with the public key to decrypt).  In nearly all cases,
    performing a signature in the standard way (with the private key
    to sign and the public key to verify) is preferred and
    recommended.
    
    Hursley defect: 190326.
    
    Affects ibmjceprovider.jar.  Available in 5.0 SR 14, 6.0 SR11,
    6.0_26 SR 3, and 7.0 SR 5
    
    Jar build date: 20120404
    
    WORKAROUNDS:
    
    None

 

### RSA解密算法的Python实现 为了理解如何用Python实现RSA解密算法,先了解其背后的数学基础。对于给定的一组公钥\( (n,e) \)和私钥\( d \),其中\( n=p*q \),\( p \)和\( q \)是两个大素数;\( e \)是一个小于\( φ(n)=(p−1)(q−1) \)并与之互质的小整数;而\( d \)则是\( e \)关于\( φ(n) \)的模逆元[^1]。 当拥有上述参数后,可以按照以下方式执行解密操作: - 假设接收到的密文为`c'`; - 利用私钥中的`d`以及公钥中的`n`来恢复原始消息`m'`,通过计算 \( m'=c'^{d}\bmod{n} \)[^2]; - 如果最初的消息是以某种编码形式被转换成整数,则最后一步还需要将此整数值重新映射回原来的形式。 下面给出一段简单的Python代码用于演示这一过程: ```python def modular_exponentiation(base, exponent, modulus): result = 1 while exponent > 0: if exponent % 2 == 1: result = (result * base) % modulus exponent = exponent >> 1 base = (base * base) % modulus return result def rsa_decrypt(ciphertext, private_key_d, public_modulus_n): plaintext_int = modular_exponentiation(int(ciphertext), int(private_key_d), int(public_modulus_n)) try: # Assuming the original message was encoded as ASCII string of integers. plaintext_str = ''.join([chr(i) for i in [plaintext_int]]) return plaintext_str except ValueError: raise Exception('Decryption failed or invalid input format.') # Example usage with hypothetical values for demonstration purposes only. private_key_d_example = "789" public_modulus_n_example = "123456789" encrypted_message_example = "987" decrypted_message = rsa_decrypt(encrypted_message_example, private_key_d_example, public_modulus_n_example) print(f"The decrypted message is: {decrypted_message}") ``` 请注意,在实际应用中应采用更安全的方式处理数据并确保所使用的密钥长度足够强以抵御攻击。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值