SunShade Posted May 2, 2009 at 08:21 PM Report #260922 Posted May 2, 2009 at 08:21 PM Boas pessoal, eu tou com um problema a cifrar com o Algoritmo RSA,eu utilizei num programa ao inicio o algoritmo DES/CBC/PKCS5Padding e akilo funcionava na boa agora quero utilizar o RSA nao consegui.Pensei que fosse do meu programa.Fiz entao um pequeno programa e nao funciona, vou por aki esse programa: KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(1024); KeyPair keyPair = keyPairGenerator.generateKeyPair(); PublicKey publicKey = keyPair.getPublic(); PrivateKey privateKey = keyPair.getPrivate(); Cipher c = Cipher.getInstance("RSA"); Cipher d = Cipher.getInstance("RSA"); c.init(Cipher.ENCRYPT_MODE,publicKey ); Message m = new Message ("buceta",40,23156487); byte [] forEncrypted = ObjectToByteConverter.convertToBytes(m); byte [] encrypted = c.doFinal(forEncrypted); Socket socket = new Socket ("Localhost",12345); OutputStream out = new ObjectOutputStream(socket .getOutputStream()); CipherOutputStream bd = new CipherOutputStream(out,c); bd.write(forEncrypted); ObjectInputStream in = new ObjectInputStream(socket.getInputStream()); Message help =(Message)in.readObject(); d.init(Cipher.DECRYPT_MODE,privateKey ); byte [] decrypted = d.doFinal(help.getData()); Message n =(Message)ObjectToByteConverter.convertToObject(decrypted); System.out.println(n.toString()); e o que me da sempre é : Exception in thread "main" javax.crypto.IllegalBlockSizeException: Data must not be longer than 117 bytes at com.sun.crypto.provider.RSACipher.a(DashoA13*..) at com.sun.crypto.provider.RSACipher.engineDoFinal(DashoA13*..) at javax.crypto.Cipher.doFinal(DashoA13*..) at rsapackage.Rsa.main(Rsa.java:34) alguem sabe como cifrar em RSA com cripto assimetrica? muito obrigado
cadillac Posted October 28, 2009 at 12:54 AM Report #293648 Posted October 28, 2009 at 12:54 AM amigo isto existe em java???? ObjectToByteConverter
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now