• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

PBEWithMD5AndDES Algorithm Exception

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have written the code which uses a password to encrypt and decrypt the text that I have passed. This is just the sample code that has been written. I was trying figure out how to make this work because I have to use the password for encrypting the text at one end and the same password at the other end to decrypt the encrypted text. The algorithm that I have used is PBEWithMD5AndDES. There is no compilation error but at runtime error it gives
Exception java.security.NoAlgorithmException: Algorithm not found. [SecretKeyFactory.PBEWithMD5AndDES]
This exception occurs when I try to instantaite the SecretKeyFactory object ( keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); )
I am unable to figure out why. Can someone please help me out.
publi void encrytDecrypt
{
PBEKeySpec pbeKeySpec;
PBEParameterSpec pbeParamSpec;
SecretKeyFactory keyFac;
// Salt
byte[] salt = {
(byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
(byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
};
// Iteration count
int count = 20;
try
{
// Create PBE parameter set
pbeParamSpec = new PBEParameterSpec(salt, count);
// Prompt user for encryption password.
// Collect user password as char array (using the
// "readPasswd" method from above), and convert
// it into a SecretKey object, using a PBE key
// factory.
String pass = "shweta";
System.out.print("Enter encryption password: ");
System.out.flush();
pbeKeySpec = new PBEKeySpec(pass.toCharArray());
keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
// Create PBE Cipher
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
// Initialize PBE Cipher with key and parameters
pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
// Our cleartext
byte[] cleartext = "This is another example".getBytes();
// Encrypt the cleartext
byte[] ciphertext = pbeCipher.doFinal(cleartext);
System.out.println("before encrypted text "+cleartext);
System.out.println("the encrypted text "+ciphertext);
pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
// Decrypt the ciphertext
byte[] cleartext1 = pbeCipher.doFinal(ciphertext);
System.out.println("the decrypted text "+cleartext1);
}
Thanks and Regards,
Shweta
 
A magnificient life is loaded with tough challenges. En garde tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic