首先:java的加密解密模块需要更加精细的算法细节指定

java的加密方式

javax.crypto.Cipher,定义的获取方式

tatic Cipher    getInstance(String transformation)
Returns a Cipher object that implements the specified transformation.
static Cipher getInstance(String transformation, Provider provider)
Returns a Cipher object that implements the specified transformation.
static Cipher getInstance(String transformation, String provider)
Returns a Cipher object that implements the specified transformation.

有两个重要参数:

1. transformation定义为

A transformation is a string that describes the operation (or set of operations) to be performed on the given input, to produce some output. A transformation always includes the name of a cryptographic algorithm (e.g., AES), and may be followed by a feedback mode and padding scheme.

A transformation is of the form:

"algorithm/mode/padding" or
"algorithm"
(in the latter case, provider-specific default values for the mode and padding scheme are used). For example, the following is a valid transformation: Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");

transformation有以下几种:

Every implementation of the Java platform is required to support the following standard Cipher transformations with the keysizes in parentheses:
AES/CBC/NoPadding (128)
AES/CBC/PKCS5Padding (128)
AES/ECB/NoPadding (128)
AES/ECB/PKCS5Padding (128)
DES/CBC/NoPadding (56)
DES/CBC/PKCS5Padding (56)
DES/ECB/NoPadding (56)
DES/ECB/PKCS5Padding (56)
DESede/CBC/NoPadding (168)
DESede/CBC/PKCS5Padding (168)
DESede/ECB/NoPadding (168)
DESede/ECB/PKCS5Padding (168)
RSA/ECB/PKCS1Padding (1024, 2048)
RSA/ECB/OAEPWithSHA-1AndMGF1Padding (1024, 2048)
RSA/ECB/OAEPWithSHA-256AndMGF1Padding (1024, 2048)
These transformations are described in the Cipher section of the Java Cryptography Architecture Standard Algorithm Name Documentation. Consult the release documentation for your implementation to see if any other transformations are supported.

2.provider

可以通过Security.getProviders()查看

        java.security.Provider [] providers=Security.getProviders();
for(int i=0;i<providers.length;i++){
System.out.println(providers[i].getName());
}

具体的provider如下:

SUN
SunRsaSign
SunEC
SunJSSE
SunJCE
SunJGSS
SunSASL
XMLDSig
SunPCSC
SunMSCAPI

python的加密方式需要到具体的代码里面了,如

from crypto.PublicKey import RSA
from crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
# from Crypto.Signature import PKCS1_v1_5 as Signature_pkcs1_v1_5 def rsaEncrypt(message):
key = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCYLCumWz6MGHmAMLIaPt3SItIhMYHuyLn48muQz2xKj9PVqETGfjq/GTxHE3wfvGCEs/JXY1rV4uysUuAS/xwZuyJ9j+sB599lzmpxdhIWu/jGMR0h86nnpNUcssYwR3Bww3oU5+dYEtGpfOytMyh3eJeUZiNNBXqH+IaSYfU3hwIDAQAB'
key1=base64.b64decode(key)
rsaKey=RSA.importKey(key1)
cipher=Cipher_pkcs1_v1_5.new(rsaKey)
temp=cipher.encrypt(message)
return binascii.b2a_hex(temp)
if __name__ == '__main__':
rsaEncrypt(13950346593)

进入encypt方法中:

    def encrypt(self, message):
"""Produce the PKCS#1 v1.5 encryption of a message. This function is named ``RSAES-PKCS1-V1_5-ENCRYPT``, and it is specified in
`section 7.2.1 of RFC8017
<https://tools.ietf.org/html/rfc8017#page-28>`_. :param message:
The message to encrypt, also known as plaintext. It can be of
variable length, but not longer than the RSA modulus (in bytes) minus 11.
:type message: bytes/bytearray/memoryview :Returns: A byte string, the ciphertext in which the message is encrypted.
It is as long as the RSA modulus (in bytes). :Raises ValueError:
If the RSA key length is not sufficiently long to deal with the given
message.
"""

发现其支持的是

PKCS#1 v1.5 encryption

对应java的模式是:

RSA/ECB/PKCS1Padding (1024, 2048)

IvParameterSpec

This class specifies an initialization vector (IV). Examples which use IVs are ciphers in feedback mode, e.g., DES in CBC mode and RSA ciphers with OAEP encoding operation.

参考文献:

【1】https://docs.oracle.com/javase/7/docs/api/javax/crypto/Cipher.html#getInstance(java.lang.String)

【2】https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#Cipher

【3】https://docs.oracle.com/javase/7/docs/api/javax/crypto/spec/IvParameterSpec.html

python vs java的rsa加密的更多相关文章

  1. JAVA实现RSA加密,非对称加密算法

    RSA.java package org.icesnow.jeasywx.util.security; import java.security.Key; import java.security.K ...

  2. Java使用RSA加密解密及签名校验

    该工具类中用到了BASE64,需要借助第三方类库:javabase64-1.3.1.jar注意:RSA加密明文最大长度117字节,解密要求密文最大长度为128字节,所以在加密和解密的过程中需要分块进行 ...

  3. C# 与JAVA 的RSA 加密解密交互,互通,C#使用BouncyCastle来实现私钥加密,公钥解密的方法

    因为C#的RSA加密解密只有公钥加密,私钥解密,没有私钥加密,公钥解密.在网上查了很久也没有很好的实现.BouncyCastle的文档少之又少.很多人可能会说,C#也是可以的,通过Biginteger ...

  4. Java使用RSA加密解密签名及校验

    RSA加密解密类: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...

  5. Java采用RSA加密及解密技术的有关Maven项目的配置流程:

    第一步: 获得RSA公钥私钥(秘钥格式:PKCS#8 ,测试使用的是无私钥密码的) 公钥: -----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4G ...

  6. php与JAVA的RSA加密互通

    Java 版本RSA 进行加密解密 在网上查询了好几天,最终找到解决方案,网络上都是通过Cipher.getInstance("RSA"); 而改成Cipher.getInstan ...

  7. JAVA实现RSA加密解密 非对称算法

    首先RSA是一个非对称的加密算法.所以在使用该算法加密解密之前,必须先行生成密钥对.包含公钥和私钥 JDK中提供了生成密钥对的类KeyPairGenerator,实比例如以下: public stat ...

  8. python 调用java脚本的加密(没试过,先记录在此)

    http://lemfix.com/topics/344 前言 自动化测试应用越来越多了,尤其是接口自动化测试. 在接口测试数据传递方面,很多公司都会选择对请求数据进行加密处理. 而目前为主,大部分公 ...

  9. iOS and JAVA 的 RSA 加密解密 (转载整理 )

    参考原文地址:http://www.cnblogs.com/makemelike/articles/3802518.html (至于RSA的基本原理,大家可以看 阮一峰的网络日志 的 RSA算法原理( ...

随机推荐

  1. python 【第三篇】函数基础

    深浅拷贝 set是一个无序且不重复的元素集合访问速度快天生解决重复问题 #!/usr/bin/env python3 # -*- coding:utf-8 -*- #深浅拷贝 import copy ...

  2. Tomcat9无法启动

    闲来无事,重新学习一下Java, 去Tomcat官网下载Tomcat,各种版本,7-8-9,果断下载最新的9,解压后,无需安装,到bin文件夹下启动, 结果总是一闪而过,百度: 1.查看8080是否占 ...

  3. Struts 1 Struts 2

    Key Technologies Primer https://struts.apache.org/primer.html Threads With Struts 1 you were require ...

  4. 转:目前为止最全的微信小程序项目实例

    wx-gesture-lock  微信小程序的手势密码 WXCustomSwitch 微信小程序自定义 Switch 组件模板 WeixinAppBdNovel 微信小程序demo:百度小说搜索 sh ...

  5. nextLine() 、nextInt()的跳过问题

    nextInt()  将输入的信息的下一个标记扫描为 int. nextLine() 此扫描器执行当前行,并返回跳过的输入信息. nextInt 会读取下面输入的 int类型的信息以回车作为结束,如果 ...

  6. js控制页面显示

    两个菜单切换显示页面内容: js控制代码, /** JS初始化 **/ $(document).ready(function() { $('#email_btn').click(function(){ ...

  7. BZOJ_3105_[cqoi2013]新Nim游戏_线性基+博弈论

    BZOJ_3105_[cqoi2013]新Nim游戏_线性基+博弈论 Description 传统的Nim游戏是这样的:有一些火柴堆,每堆都有若干根火柴(不同堆的火柴数量可以不同).两个游戏者轮流操作 ...

  8. 【转】Echarts的使用以及动态加载数据

    一.Echarts的介绍 ECharts开源来自百度商业前端数据可视化团队,基于html5 Canvas,是一个纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据可视化图表.创新 ...

  9. uCos-III移植到STM32F10x

    最近在百度上看了uCOS-III 的介绍后,诸多功能有很大的提升和改进,感觉有必要升级一下开发环境.百度介绍:http://baike.baidu.com/view/8531313.htm 环境: S ...

  10. WIN8系统的远程桌面漏洞 利用QQ拼音纯净版实现提权

    前言 发现这个漏洞的时候, 笔者正在机房上课.正想用3389远程桌面去控制宿舍电脑的时候,因为重做系统忘记自己的IP地址,因此就随手扫描了一下IP段开3389端口的电脑. 没想到就随手扫描到一台WIN ...