RSA encryption for Python vs Java

Source: Internet
Author: User
Tags modulus

First: The cryptographic decryption module for Java requires more granular algorithm details to specify

How Java is encrypted

Javax.crypto.Cipher, definition of how to obtain

tatic Cipher     Implements The specified transformation. Static Cipher     Implements The specified transformation. Static Cipher     implements the specified transformation.

There are two important parameters:

1. Transformation is defined as

a transformation is a string this describes the operation (or set of operations) to being performed on the given input, T o Produce some output.  A transformation always includes the name of a cryptographic algorithm (e.g., AES), and May is followed by a feedback mode and padding scheme. A Transformationis of the form: "Algorithm/mode/padding" or"algorithm" case Default for the mode and padding scheme is used). For example, the following is a valid transformation:     = cipher.getinstance ("aes/cbc/pkcs5padding");

Transformation have the following types:

every implementation of the Java platform is required to support the following standard Cipher transformations with th E 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 is described in the Cipher sections of the Java Cryptography Architecture Standard algorithm Na Me documentation. Consult the release documentation forYour implementation to seeifAny other transformations is supported.

2.provider

Can be viewed via security.getproviders ()

        Java.security.Provider [] providers=security.getproviders ();          for (int i=0;i<providers.length;i++) {            System.out.println (Providers[i].getname ());        }

The specific provider are as follows:

Sunsunrsasignsunecsunjssesunjcesunjgsssunsaslxmldsigsunpcscsunmscapi

The Python encryption method needs to be in the specific code, such as

 fromCrypto. PublicKeyImportRSA fromCrypto. CipherImportPkcs1_v1_5 as Cipher_pkcs1_v1_5#From crypto.signature import pkcs1_v1_5 as Signature_pkcs1_v1_5defrsaencrypt (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)returnBinascii.b2a_hex (temp)if __name__=='__main__': Rsaencrypt (13950346593)

Enter the Encypt method:

    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's specified in ' sections        7.2.1 of RFC8017         """

Found it supported by

Pkcs#1 v1.5 Encryption

The patterns corresponding to Java are:

Rsa/ecb/pkcs1padding (1024x768, 2048)

Reference documents:

"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

RSA encryption for Python vs Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.