• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Cryptography!!!  RSS feed

 
raghavender rao
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ther,
i am trying to implement this prg on servlets but it says
Algorithm not found...but the code is working perfectly on the console.....
import java.io.*;
import com.dstc.security.provider.*;
import javax.crypto.*;
import javax.crypto.Cipher.*;
import java.security.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.security.spec.*;
import java.security.interfaces.*;

public class EncryptServlet extends HttpServlet {

PrintWriter out;
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException {
try {



out = res.getWriter();
String text = "Hello";


out.println("Generating a DESede (TripleDES) key...");
// Create a TripleDES key


KeyGenerator keyGenerator = KeyGenerator.getInstance("DES");
// KeyGenerator keyGenerator = KeyGenerator.getInstance("PBEwithMD5andDE5-CBC");

keyGenerator.init(56); // need to initialize with the keysize
Key key = keyGenerator.generateKey();

String keyy = key.toString();
out.println("Done generating the key and the key is ... "+keyy);

// Create a cipher using that key to initialize it

// Cipher cipher = Cipher.getInstance("PBEwithMD5andDE5-CBC");


Cipher cipher = Cipher.getInstance("DES");

out.println("The Value of "+text);


cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] plaintext = text.getBytes("UTF8");

// Print out the bytes of the plaintext
//out.println("\nPlaintext: "+plaintext);


for (int i=0;i<plaintext.length;i++) {


out.print(plaintext[i]+" ");
}
// Perform the actual encryption
byte[] ciphertext = cipher.doFinal(plaintext);
// Print out the ciphertext
out.println("\n\nCiphertext: ");
String s=null;
for (int i=0;i<ciphertext.length;i++) {


out.print(ciphertext[i]+" ");


}
s = ciphertext.toString();
out.println("The CypherText is "+s);
// Re-initialize the cipher to decrypt mode
cipher.init(Cipher.DECRYPT_MODE, key);

// Perform the decryption
byte[] decryptedText = cipher.doFinal(ciphertext);
String output = new String(decryptedText,"UTF8");
out.println("\n\nDecrypted text: "+output);
}
catch(Exception e){

out.println(e.getMessage()); }

}


}
please do help me asap..
Rao
 
Dorj Galaa
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must register your provider
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's easiest if you follow the instructions for installing JCE as an installed extension.
- Peter
 
David Bejjam
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Algorithm not found by KeyGenerator or Cipher ?
 
Jamie Young
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cipher cipher = Cipher.getInstance("DES");
What object Cipher?
What does it do?
What package is it from?
Just curious.
 
raghavender rao
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

i tried registering provider dynamically
Security.addProvider(new DSTC());
where DSTC is a Security Provider...
Mr Peter i cant download JCE coz i am not in Canada or US....
Algorithm not found by KeyGenerator....

Mr Jamie Cipher is a class in javax.crypto
package com.dstc.*;
please help to solve this problem

 
David Bejjam
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
JCE is now downloadable even outside US, check it out at the javasoft site. Try out your programs with jdk1.4beta becoz JCE is bundeled with it.
bye
 
raghavender rao
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi sir.
i tried using jdk1.4 but it dosent work with servlets

Rao
 
raghavender rao
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi sir.
i tried using jdk1.4 but it dosent work with servlets

Rao
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!