• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

crytography

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just tell me the procedures how to encrypt the incoming string(i.e. any variable may be String ui="fdfdfd" and the information stored in the file.
------------------
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this code wil work perfectly

import java.io.*;
import com.dstc.security.provider.*;
import javax.crypto.*;
import javax.crypto.Cipher.*;
import java.security.*;
import java.security.spec.*;
import java.security.interfaces.*;


public class EncTest {


public static void main(String args[]){


//String text = "Hello";


EncTest t = new EncTest();

}
public EncTest(){


try {
String text = "RAO";

System.out.println();
System.out.println();
System.out.println("Generating a DESede (TripleDES) key...");
// Create a TripleDES key
System.out.println();
System.out.println();
KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyStore.getDefaultType());

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

keyGenerator.init(56); // need to initialize with the keysize

Key key = keyGenerator.generateKey();

String keyy = key.toString();

System.out.println();
System.out.println();
System.out.println("Done generating the key and the key is ... "+keyy);

//System.out.println("The Security Manager is"+System.getSecurityManager());


//Create a cipher using that key to initialize it

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


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


System.out.println();
System.out.println();
System.out.println("The Given Text is "+text);


cipher.init(Cipher.ENCRYPT_MODE, key);

byte[] plaintext = text.getBytes("UTF8");

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


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



System.out.print(plaintext[i]+" ");



}
// Perform the actual encryption

byte[] ciphertext = cipher.doFinal(plaintext);
// Print System.out the ciphertext

System.out.print("\n\nCiphertext: ");
String s=null;
for (int i=0;i<ciphertext.length;i++) {


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


}

System.out.println();
System.out.println();
s = ciphertext.toString();
System.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");

System.out.println();
System.out.println();
System.out.println("\n\nDecrypted text: "+output);
}catch(Exception e){


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

}

}


}
//Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
//Cipher cipher = Cipher.getInstance("PBEwithMD5andDE5-CBC");

for further doubts mail me bk...
Rao
 
This tiny ad is suggesting that maybe she should go play in traffic.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic