Sign in to follow this  
gorgorath

[java] encryption problem

Recommended Posts

I'm wondering why the following doesn't work: Cipher encrypt = Cipher.getInstance("RSA"); encrypt.init(Cipher.ENCRYPT_MODE, key); ByteArrayInputStream str = new ByteArrayInputStream(data); CipherInputStream cis = new CipherInputStream(str, encrypt); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte tmp[] = new byte[8]; int i = cis.read(tmp); while (i != -1) { out.write(tmp, 0, i); i = cis.read(tmp); } //WORKS ALWAYS TILL 52 characthers //return encrypt.doFinal(data); //this DON"T WORK AL the times buyt sometimes does return out.toString().getBytes(); the doFinal method always works but only upto 52 bytes probably i'm overlooking sth. but can't see directly waht

Share this post


Link to post
Share on other sites
Wild guess, but is the key 52 charactors? if it's the same length as the key, then you need to make a loop to make sure it loops through the key as many times as necessary. That was a problem I had when I was writing some basic encryption in Turing for a programming contest, and I ran out of time..

But yeah, that could be the problem. (sorry I can't offer a solution, since I'm not used to encryption in Java and would code everything myself, i can't help with java's interface, it could just be that you need to encode each 52 character string one at a timeand out put them each time, ro something liek that)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this