vb.net - RSA Cypher VisualBasic to Java -
I'm having trouble encrypting some strings in Java, I need to encrypt it with the VisualBasic code in the same way:
public function encrypt (as KeyPair, as in the use of public key to encrypt // in as the wild plaintext string) string M_objRSAkFromXmlString (Ankripshnkeepiyr .m. Get it and compare it with the length of plain text // If the length of plain text is gt; (Modulus size - 11), then plain text would need to break into pieces the size (modulus size - 11) // will be encrypted separately to each segment of them // and at least 11 bytes padding) // When If decrypting, then encrypted text string & gt; The modulus size will be divided into sections of this size, which will be equal to the modulus size. // Each of these encrypted text segments will be decrypted separately, resulting in plain text segments re-assembled. String = "as dim intBlockSize = GetModulusSize (EncryptionKeyPair.PublicKey.Key) - 11 dim strencryptedText as integer" while Lane (plaintext) & gt; 0 If lane (plaintext) & gt; IntBlockSize then strencryptedText = strencryptedText & amp; Ankriptblok (Left (plaintext, Intbloksijh)) plaintext = Right (plaintext, Lane (plaintext) - Intbloksijh) Other Strennkripted text = Strenkripted text & amp; EncryptBlock (plaintext) plaintext = "end" if the ends do return Strennkripted text End Function Private Function Ankriptedblok (Ararapi Ararsapiaraiader as Arsakrripto service provider, the byline Strin) string returns byte Arreststring (The Arsapraivr as string. (Encrypted StringAsbiteArere (LRN), Failure As Function Function GetModulusSize (W) As Arnank ByVal intKeySize) is as integer / / KeySize bits - Receive # bytes divided by 8 intKeySize / 8 End Function
I already have it I have searched the Internet and I have not found anything like this. I have a public key from modulus and exponent and I am doing this:
byte [] expBytes = Base64.decode (exponent .tim ()); byte [] modBytes = Base64.decode (modulus.trim ()); Bigtegger module = new bigigner (1, modibits); b Intejr exponents = new Bigintegr (1, Aksbibets); Kifaritr Factory = Kifariti. Get Instance ("RSA"); Cipher cipher = cipher Get Instances ("RSA / ECB / PKCS 1 Padding"); RSAPublicKeySpec pubSpec = New RSAPublicKeySpec (module, exponents); Public's public sector = factory. GenerPublic (pubSpec); Cipher It (cipher NCRYPMYEEE, Pubke); Byte [] Encrypted = Cipher.Doghanal (field. GetBytes ("UTF-16LE")); String string = new string (encrypted);
The result is not correct because I am not doing anything about the modulus size - 11. Can you please tell me how can I do this in Java?
Thank you.
Modulus size is not a problem Problems are more likely that you are expecting similar values. They are not even in the VB code or java code itself (run the code snippet twice!). RSA PKCS # 1 v1.5 padding has a random number, ensuring that encryption will always give results of a different value. It is similar to OEP padding similarly.
Note that instead of what you are doing now you can see OEP mode and a hybrid cryptosystem. You will be safe and you will be able to handle the data of any size, although the quantity of ciphertext will be very high.
Comments
Post a Comment