*
The moose likes Security and the fly likes Algorithm DES not available Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "Algorithm DES not available" Watch "Algorithm DES not available" New topic
Author

Algorithm DES not available

ChengKuan Gan
Greenhorn

Joined: Oct 15, 2004
Posts: 2
I am using JDK 1.4.1_04 and I got the following error.

java.security.NoSuchAlgorithmException: Algorithm DES not available
at javax.crypto.SunJCE_b.a(DashoA6275)
at javax.crypto.KeyGenerator.getInstance(DashoA6275)
at SymmetricCipherTest.main(SymmetricCipherTest.java:29)

this is my code:

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.Cipher;

public class SymmetricCipherTest {
private static byte[] iv =
{ 0x0a, 0x01, 0x02, 0x03, 0x04, 0x0b, 0x0c, 0x0d };

private static byte[] encrypt(byte[] inpBytes,
SecretKey key, String xform) throws Exception {
Cipher cipher = Cipher.getInstance(xform);
IvParameterSpec ips = new IvParameterSpec(iv);
cipher.init(Cipher.ENCRYPT_MODE, key, ips);
return cipher.doFinal(inpBytes);
}

private static byte[] decrypt(byte[] inpBytes,
SecretKey key, String xform) throws Exception {
Cipher cipher = Cipher.getInstance(xform);
IvParameterSpec ips = new IvParameterSpec(iv);
cipher.init(Cipher.DECRYPT_MODE, key, ips);
return cipher.doFinal(inpBytes);
}

public static void main(String[] unused) throws Exception {
String xform = "DES/ECB/PKCS5Padding";
// Generate a secret key
KeyGenerator kg = KeyGenerator.getInstance("DES");
kg.init(56); // 56 is the keysize. Fixed for DES
SecretKey key = kg.generateKey();

byte[] dataBytes =
"J2EE Security for Servlets, EJBs and Web Services".getBytes();

byte[] encBytes = encrypt(dataBytes, key, xform);
byte[] decBytes = decrypt(encBytes, key, xform);

boolean expected = java.util.Arrays.equals(dataBytes, decBytes);
System.out.println("Test " + (expected ? "SUCCEEDED!" : "FAILED!"));
}
}

when run the following codes to list the crypto service and implementation,

String[] cryptoType = CryptoService.getServiceTypes();
for(int i=0; i<cryptoType.length; i++){
System.out.println("=============================");
System.out.println(cryptoType[i]);
System.out.println("=============================");
String[] impl = CryptoService.getCryptoImpls(cryptoType[i]);
for(int j=0; j<impl.length; j++){
System.out.println(impl[j]);
}
}

I have the following out put:

=============================
TrustManagerFactory
=============================
SunX509
=============================
CertPathValidator
=============================
PKIX
=============================
SSLContext
=============================
TLS
SSL
TLSv1
SSLv3
=============================
CertStore
=============================
Collection
LDAP
=============================
AlgorithmParameterGenerator
=============================
DSA
DiffieHellman
DH
=============================
KeyGenerator
=============================
TripleDES
Blowfish
DESede
HmacMD5
HmacSHA1
DES
=============================
Mac
=============================
HmacMD5
HmacSHA1
=============================
Cipher
=============================
TripleDES
PBEWithMD5AndDES
Blowfish
DESede
PBEWithMD5AndTripleDES
DES
=============================
Signature
=============================
MD2withRSA
OID.1.2.840.10040.4.3
1.3.14.3.2.13
SHAwithDSA
DSAWithSHA1
1.3.14.3.2.27
DSA
1.2.840.10040.4.3
SHA1withRSA
SHA/DSA
SHA-1/DSA
SHA1withDSA
MD5withRSA
DSS
SHA1/DSA
=============================
KeyStore
=============================
PKCS12
JKS
JCEKS
=============================
MessageDigest
=============================
SHA1
SHA
SHA-1
MD5
=============================
SecureRandom
=============================
SHA1PRNG
=============================
KeyPairGenerator
=============================
RSA
DSA
1.2.840.10040.4.1
DiffieHellman
DH
1.3.14.3.2.12
OID.1.2.840.10040.4.1
=============================
CertificateFactory
=============================
X509
X.509
=============================
KeyManagerFactory
=============================
SunX509
=============================
AlgorithmParameters
=============================
TripleDES
PBEWithMD5AndDES
DSA
Blowfish
1.2.840.10040.4.1
DiffieHellman
DESede
DH
1.3.14.3.2.12
DES
PBE
=============================
KeyAgreement
=============================
DiffieHellman
DH
=============================
SecretKeyFactory
=============================
TripleDES
PBEWithMD5AndDES
DESede
DES
=============================
GssApiMechanism
=============================
1.2.840.113554.1.2.2
=============================
KeyFactory
=============================
RSA
DSA
1.2.840.10040.4.1
DiffieHellman
DH
1.3.14.3.2.12
=============================
CertPathBuilder
=============================
PKIX

Seems like the service and implementation is available. I do not know where is the mistake.

Can anyone please help me...

Regards,
ChengKuan, Gan
xiaotaoliang
Greenhorn

Joined: Dec 15, 2004
Posts: 1
J2SDK comes standard with a cryptographic service provider named "SUN" (which supplies an implementation of the MD5 message digest algorithm), and JCE 1.2.1 comes standard with a different provider named "SunJCE" (which implements a session key generator for DES). While the "SUN" provider is registered automatically, the "SunJCE" provider needs to be registered explicitly.
Please refer to the installation guide for directions on how to register the "SunJCE" provider. Once you have registered the "SunJCE" provider, the above exception will disappear.
ChengKuan Gan
Greenhorn

Joined: Oct 15, 2004
Posts: 2
xiaotaoliang, thank you for your suggestion.

By right JDK1.4 should statically registers the SunJCE since sunJCE is part of JDK1.4, which also can be seen in the JRE's java.security file. However, the provider only registered when I calls the following codes in my Java codes:

java.security.Security.addProvider(new com.sun.crypto.provider.SunJCE());

anyway, thank you for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Algorithm DES not available
 
Similar Threads
Jdk14 Cipher Providers Exceptions
IllegalBlockSizeException while decrypting using Triple DES
Triple DES with Cipher Block Chaining - Beginner que
InvalidKeyException in 3DES
Triple Des Pin Encryption