Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #4311

Re: java.security.InvalidKeyException: Wrong key size

Newsgroups comp.lang.java.help
Date 2020-03-09 09:55 -0700
References <9d1b8fe8af350eb563c30c7d49e57a33@localhost.talkaboutprogramming.com>
Message-ID <106d16a2-0428-4b74-a042-6b7c4e26bf12@googlegroups.com> (permalink)
Subject Re: java.security.InvalidKeyException: Wrong key size
From samquetinuel@gmail.com

Show all headers | View raw


Le mardi 2 novembre 2004 21:43:43 UTC+1, dmak a écrit :
> Hi,
> 
> I am trying to encrypt a string using MD5. Following is the piece of code.
> I get the error "java.security.InvalidKeyException: Wrong key size" at the
> following line
> 
>    DESedeKeySpec desedeKeySpec = new DESedeKeySpec(pwdhash);
> 
> Any help is appreciated . Thank U
> 
> Code:-
>   public static void main (String args[]) {
>     arg = args[0];
> 
>     try {
>       password = "secretpassword1!";
>       MessageDigest md = MessageDigest.getInstance("MD5");
>       pwdhash = md.digest(password.getBytes());
>       md = null;
>       DESedeKeySpec desedeKeySpec = new DESedeKeySpec(pwdhash);
>       System.out.println("Work");
>       SecretKeyFactory keyFactory =
> SecretKeyFactory.getInstance("DESede");
>       Key desKey = (Key) keyFactory.generateSecret(desedeKeySpec);
>       desCipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
>       desCipher.init(Cipher.ENCRYPT_MODE, desKey);
>     }
>     catch(Exception e) {
>       System.out.println("e "+e);
>     }
> 
>     String encr = encrypt(arg);
>   }

wtf

Back to comp.lang.java.help | Previous | Next | Find similar


Thread

Re: java.security.InvalidKeyException: Wrong key size samquetinuel@gmail.com - 2020-03-09 09:55 -0700

csiph-web