
Encryption code&Decryption code Iam developing a web security application for that reason i need a code of encryption &Decryption in servlet. Can u please send it to me.Its very urgent Because my project delivery date is very near

import java.io.*; import java.security.*; import javax.crypto.*;
class EncryptAndDecrypt {
public static void main (String[] args) throws Exception{ KeyPairGenerator keygenerator = KeyPairGenerator.getInstance("RSA"); SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN"); keygenerator.initialize(1024, random);
KeyPair keypair = keygenerator.generateKeyPair(); PrivateKey privateKey = keypair.getPrivate(); PublicKey publicKey = keypair.getPublic(); Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey); String st= "roseindia"; byte[] cleartext = null; cleartext = st.getBytes(); byte[] ciphertext = null; ciphertext = cipher.doFinal(cleartext); System.out.println("the encrypted text is: " + ciphertext.toString());
cipher.init(Cipher.DECRYPT_MODE, privateKey); byte[] cleartext1 = cipher.doFinal(ciphertext); System.out.println("the decrypted cleartext is: " + new String(cleartext1)); } }
make a package and import it into servlet or write this code in servlet directly also
take care have a nice day
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.