byte[] Expbytes =base64.decodebase64 (Exponentelem.gettext (). Trim ()));byte[] Modbytes =base64.decodebase64 (Moduluselem.gettext (). Trim ());byte[] Dbytes =base64.decodebase64 (Delem.gettext (). Trim ()); BigInteger Modules=NewBigInteger (1, modbytes); BigInteger exponent=NewBigInteger (1, expbytes); BigInteger D=NewBigInteger (1, dbytes); Keyfactory Factory= Keyfactory.getinstance ("RSA"); Cipher Cipher= Cipher.getinstance ("RSA"); String input= "Test"; Rsapublickeyspec Pubspec=NewRsapublickeyspec (modules, exponent); PublicKey PubKey=factory.generatepublic (Pubspec); Cipher.init (Cipher.encrypt_mode, PubKey);byte[] encrypted = Cipher.dofinal (Input.getbytes ("UTF-8")); System.out.println ("Encrypted:" +NewString (encrypted)); Rsaprivatekeyspec Privspec=NewRsaprivatekeyspec (modules, D); Privatekey Privkey=factory.generateprivate (Privspec); Cipher.init (Cipher.decrypt_mode, privkey);byte[] decrypted =cipher.dofinal (encrypted); System.out.println ("Decrypted:" +NewString (decrypted));
Porting. Net RSA XML keys to Java