首先: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. ubuntu下spring环境搭建

    一.安装JDK 下载官网:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 部署: ...

  2. Linux下通过find命令进行rm文件删除的小技巧

       我们常常会通过find命令进行批量操作.如:批量删除旧文件.批量改动.基于时间的文件统计.基于文件大小的文件统计等.在这些操作其中,因为rm删除操作会导致文件夹结构变化,假设要通过find结合r ...

  3. 浅谈UML学习笔记之用例图

    最近一直在学习UML的基础知识,再看完视频之后,并没有很好的总结,在画图的过程中发现了很多的问题,下面是看书的过程自己总结的UML用例图的一点知识,与大家分享一下. 一.概念 用例图是由参与者.用例以 ...

  4. Nginx——静态资源服务器(一)

    java web的项目中,我们经常将项目部署到Tomcat或者jetty上,可以通过Tomcat或者jetty启动的服务来访问静态资源.但是随着Nginx的普及,用Nginx来作为静态资源服务器,似乎 ...

  5. (1)JDBC基础-java链接mysql数据库

    怎么操作数据库: 1,通过客户端(比如mac的终端,或者sql pro等专业工具)登陆数据库服务器(mysql -u root -p) 2,编写sql语句 3,发生sql语句到数据库服务器执行. JD ...

  6. Uvalive 4043 Ants —— 二分图最大权匹配 KM算法

    题目链接:https://vjudge.net/problem/UVALive-4043 题意: 给出n个白点和n个黑点的坐标, 要求用n条不相交的线段把他们连接起来,其中每条线段恰好连接一个白点和黑 ...

  7. Android Studio3.1.0升级问题记录

    每次升级Android Studio时,一般情况下Gradle版本的也会相应的升级,我之前Android Studio 3.0.1.Gradle 是4.1升级后为:Android Studio 3.1 ...

  8. Java对象与对象引用变量的理解

    Java对象及对象引用 首先定义一个简单的类: class User{ int userId; String userName; } 我们在创建对象时,通常会写: User user = new Us ...

  9. ios app 上架AppStore

    一.证书的导出      1.1 前期工作        首先你需要有一个苹果的开发者帐号,一个Mac系统.        如果没有帐号可以在打开http://developer.apple.com/ ...

  10. C语言算法

    选择排序法:用第一个数分别和后面的数比较 冒泡排序法:相邻的两个数比较 01.单词首字母大写&统计单词个数 02: 编写一个函数int pieAdd(int n),计算1!+2!+3!+……+ ...