You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Shshank Jain <ja...@gmail.com> on 2006/06/09 09:10:19 UTC
Encryption / decryption problem in multi threading
Hii
I m having this strange problem.
I m encrypting the password using java JCE AES encryption algorithm and
storing the password as varchar(30) in the mySQL database. The
Encryption/Decryption is working fine
if i am doing it sequentially (single thread) but i m getting a
javax.crypto.BadPaddingException: Given final block not properly padded
............
exception when i am running a multi threaded test !!
any ideas ??
- Shanky
Re: [OT] Re: Encryption / decryption problem in multi threading
Posted by Shshank Jain <ja...@gmail.com>.
yup encoding was the main issue and i had also not made the encrypt/decrypt
function synchronized , these were the two problems
On 6/10/06, Scott Van Wart <sc...@indosoft.ca> wrote:
>
> Shshank Jain wrote:
> > the problem was muti threading (the sychronized block) plus the
> > database had
> > the password field as varchar
> > i encoded the data and make the character encoding base 64 (
> > http://forum.java.sun.com/thread.jspa?threadID=555631&messageID=2729521)
> > and it works now
>
> So was it solely the encoding issue? I've always made sure to base64
> any binary data that absolutely had to be stored in a char-derived
> column; was this the only issue?
>
> - Scott
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: [OT] Re: Encryption / decryption problem in multi threading
Posted by Scott Van Wart <sc...@indosoft.ca>.
Shshank Jain wrote:
> the problem was muti threading (the sychronized block) plus the
> database had
> the password field as varchar
> i encoded the data and make the character encoding base 64 (
> http://forum.java.sun.com/thread.jspa?threadID=555631&messageID=2729521)
> and it works now
So was it solely the encoding issue? I've always made sure to base64
any binary data that absolutely had to be stored in a char-derived
column; was this the only issue?
- Scott
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Re: Encryption / decryption problem in multi threading
Posted by Shshank Jain <ja...@gmail.com>.
he dave !!
problem solved !!
the problem was muti threading (the sychronized block) plus the database had
the password field as varchar
i encoded the data and make the character encoding base 64 (
http://forum.java.sun.com/thread.jspa?threadID=555631&messageID=2729521)
and it works now
Thanks for ur support.
On 6/9/06, Shshank Jain <ja...@gmail.com> wrote:
>
> i will run some test cases here and get back...
> i ran it sequentially it worked fine....
>
> On 6/9/06, Dave Newton <ne...@pingsite.com> wrote:
>
> > Shshank Jain wrote:
> > > making the decryt/encrypt synchronized didnt help
> >
> > Ok.
> >
> > Dave
> >
> > PS If the only difference is single- vs. multi-threaded then I'll almost
> > guarantee you you're walking on something, somewhere, even if it's in
> > your test code.
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
Re: [OT] Re: Encryption / decryption problem in multi threading
Posted by Shshank Jain <ja...@gmail.com>.
i will run some test cases here and get back...
i ran it sequentially it worked fine....
On 6/9/06, Dave Newton <ne...@pingsite.com> wrote:
>
> Shshank Jain wrote:
> > making the decryt/encrypt synchronized didnt help
>
> Ok.
>
> Dave
>
> PS If the only difference is single- vs. multi-threaded then I'll almost
> guarantee you you're walking on something, somewhere, even if it's in
> your test code.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: [OT] Re: Encryption / decryption problem in multi threading
Posted by Dave Newton <ne...@pingsite.com>.
Shshank Jain wrote:
> making the decryt/encrypt synchronized didnt help
Ok.
Dave
PS If the only difference is single- vs. multi-threaded then I'll almost
guarantee you you're walking on something, somewhere, even if it's in
your test code.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Re: Encryption / decryption problem in multi threading
Posted by Shshank Jain <ja...@gmail.com>.
making the decryt/encrypt synchronized didnt help
-Shanky
On 6/9/06, Dave Newton <ne...@pingsite.com> wrote:
>
> Shshank Jain wrote:
> > Thanks in advance.
>
> Still OT, but anyway.
>
> Can't read your code. I'd still check to see if you're using a
> single-instance of an unsynchronized variable so it's getting corrupted
> when being hit by multiple threads.
>
> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: [OT] Re: Encryption / decryption problem in multi threading
Posted by Dave Newton <ne...@pingsite.com>.
Shshank Jain wrote:
> Thanks in advance.
Still OT, but anyway.
Can't read your code. I'd still check to see if you're using a
single-instance of an unsynchronized variable so it's getting corrupted
when being hit by multiple threads.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Re: Encryption / decryption problem in multi threading
Posted by Shshank Jain <ja...@gmail.com>.
i have made a static instance of it in the services and do it at that
level..here is the code
----------------------------------------- code
--------------------------------------------
static {
try {
// theBigSecret : contains the 128 bit encrption key
// ENCRYPTION_ALGORITHM : "AES"
SecretKeySpec skeySpec = new SecretKeySpec(theBigSecret.getBytes(),
ENCRYPTION_ALGORITHM);
s_EncryptCipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
s_EncryptCipher.init(Cipher.ENCRYPT_MODE, skeySpec);
s_DecryptCipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
s_DecryptCipher.init(Cipher.DECRYPT_MODE, skeySpec);
} catch ()
.............. // Exception handling here
}
public static String decrypt(String s) throws
AuthenticationServiceException{
try {
return new String(s_DecryptCipher.doFinal(s.getBytes()));
} catch (...) {
// Exception Handling here
}
}
/**
* Function to encrypt the password
* @param s string to be encrypted
* @return the encrypted password
*/
public static String encrypt(String s) throws
AuthenticationServiceException{
try {
return new String(s_EncryptCipher.doFinal(s.getBytes()));
} catch (IllegalBlockSizeException e) {
//Exception handling here
}
}
-------------------------------- code ends here
----------------------------------------------------
This works with MySql Db in the single threaded case but fails in the muti
threaded case.
Thanks in advance.
On 6/9/06, Dave Newton <ne...@pingsite.com> wrote:
>
> Shshank Jain wrote:
> > any ideas ??
>
> Not without any code.
>
> If you're doing it inside a Struts Action are you using an instance
> variable in the Action?
>
> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
[OT] Re: Encryption / decryption problem in multi threading
Posted by Dave Newton <ne...@pingsite.com>.
Shshank Jain wrote:
> any ideas ??
Not without any code.
If you're doing it inside a Struts Action are you using an instance
variable in the Action?
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org