Home > Back-end >  JAVA RSA without filling encryption for help, through modeling and index for encryption
JAVA RSA without filling encryption for help, through modeling and index for encryption

Time:04-05

Existing demand through modeling and index of parameters for RSA encryption, message
Now grasp the Python code:
 import rsa 
# die
M="ae068c2039bd2d82a529883f273cf20a48e0b6faa564e740402375a9cb332a029b8492ae342893d9c9d53d94d3ab8ae95de9607c2e03dd46cebe211532810b73cc764995ee61ef435437bcddb3f4a52fca66246dbdf2566dd85fbc4930c548e7033c2bcc825b038e8dd4b3553690e0c438bbd5ade6f5a476b1cbc1612f5d501f
"# index
E='010001'
# encryption parameter
Message='123456'

The class Encrypt (object) :
Def __init__ (self, e, m) :
Self. E=e
Self. M=m

Def encrypt (self, the message) :
Mm=int (self. J m, 16)
Ee=int (self. J e, 16)
Rsa_pubkey=rsa. PublicKey (mm, ee)
Crypto=self. _encrypt (message) encode (), rsa_pubkey)
Return crypto. Hex ()

Def _pad_for_encryption (self, message, target_length) :
Message=message] [: : - 1
Max_msglength=target_length - 11
Msglength=len (message)

Padding=b '
Padding_length=target_length - msglength - 3

For I in range (padding_length) :
Padding +=b '\ x00'

Return b '. Join ([b '\ x00 \ x00, padding, b' \ x00, message])

Def _encrypt (self, message, pub_key) :
Keylength=rsa.com mon. Byte_size (pub_key. N)
Padded=self. _pad_for_encryption (message, keylength)

Content=rsa. The transform. Bytes2int (padded)
Encrypted=rsa. Core. Encrypt_int (payload, pub_key. E, pub_key. N)
Block=rsa. The transform. Int2bytes (encrypted, keylength)

The return of block

If __name__=="__main__ ':
En=Encrypt (e, m)
Print (en. Encrypt (the message))

Output: 2 ab11a1d49a4d0ba2a7cc67135219be2444229fff08eb3f869200a545833f55bd00e25dc96b5126c9649b08f953ecc0e9a2d0d9650421061cafb1e52a4b8bdbb336e662eddabd1158b16f7c5a14d29c9009e506bbdccd2af0bf94061642423173f01765bf494d6a139872b4b10535559acd2eaed3cfc8c1858764e99716bc19b
The result is the only sure,
Recently on the Internet access to information found online JAVA related implementation RSA can't satisfy the above requirements, a JAVA in the RSA encryption algorithm can meet the above requirements,
A given mode and index, and the message can be the only encrypted string,
  • Related