X-Received: by 2002:ac8:6ec3:: with SMTP id f3mr15143996qtv.328.1583772914406; Mon, 09 Mar 2020 09:55:14 -0700 (PDT) X-Received: by 2002:a25:6c0a:: with SMTP id h10mr17665057ybc.47.1583772914038; Mon, 09 Mar 2020 09:55:14 -0700 (PDT) Path: csiph.com!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.help Date: Mon, 9 Mar 2020 09:55:13 -0700 (PDT) In-Reply-To: <9d1b8fe8af350eb563c30c7d49e57a33@localhost.talkaboutprogramming.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=162.38.222.172; posting-account=cYyrQgoAAACw9RhAzhXa4LliOkBIYXiR NNTP-Posting-Host: 162.38.222.172 References: <9d1b8fe8af350eb563c30c7d49e57a33@localhost.talkaboutprogramming.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <106d16a2-0428-4b74-a042-6b7c4e26bf12@googlegroups.com> Subject: Re: java.security.InvalidKeyException: Wrong key size From: samquetinuel@gmail.com Injection-Date: Mon, 09 Mar 2020 16:55:14 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.java.help:4311 Le mardi 2 novembre 2004 21:43:43 UTC+1, dmak a =C3=A9crit=C2=A0: > Hi, >=20 > 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 th= e > following line >=20 > DESedeKeySpec desedeKeySpec =3D new DESedeKeySpec(pwdhash); >=20 > Any help is appreciated . Thank U >=20 > Code:- > public static void main (String args[]) { > arg =3D args[0]; >=20 > try { > password =3D "secretpassword1!"; > MessageDigest md =3D MessageDigest.getInstance("MD5"); > pwdhash =3D md.digest(password.getBytes()); > md =3D null; > DESedeKeySpec desedeKeySpec =3D new DESedeKeySpec(pwdhash); > System.out.println("Work"); > SecretKeyFactory keyFactory =3D > SecretKeyFactory.getInstance("DESede"); > Key desKey =3D (Key) keyFactory.generateSecret(desedeKeySpec); > desCipher =3D Cipher.getInstance("DESede/ECB/PKCS5Padding"); > desCipher.init(Cipher.ENCRYPT_MODE, desKey); > } > catch(Exception e) { > System.out.println("e "+e); > } >=20 > String encr =3D encrypt(arg); > } wtf