Skip to main content
gamedev.net
🔒 Locked

[java] encryption problem

Started by gorgorath 0 replies 500+ views
Original Post
gorgorath
gorgorath
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
Cosmic Keys to my Creations & Times
bobbias
bobbias
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)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.