This paper briefly introduces the core application of JCE framework.
Javax.crypto.Cipher This class provides password functionality for encryption and decryption. It forms the core of the Java cryptographic Extension (JCE) framework. To create the Cipher object, the application invokes the Cipher getInstance
method and passes the name of the requested transformation to it. You can also specify the name of the provider (optional).
A transformation is a string that describes an action (or a set of actions) to be performed on a given input to produce some sort of output. The conversion always includes the name of the cryptographic algorithm (for example,DES), which may be followed by a feedback pattern and a fill scheme.
Package thtf.com.cn.client;
Import Java.io.ByteArrayOutputStream;
Import Java.io.FileInputStream;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.ObjectInputStream;
Import Java.io.ObjectOutputStream;
Import Java.io.OutputStream;
Import Java.security.Key;
Import Java.security.SecureRandom;
Import Java.security.spec.AlgorithmParameterSpec;
Import java.util.ArrayList;
Import java.util.Collection;
Import Java.util.Iterator;
Import java.util.Properties;
Import Javax.crypto.Cipher;
Import Javax.crypto.CipherInputStream;
Import Javax.crypto.CipherOutputStream;
Import Javax.crypto.KeyGenerator;
Import Javax.crypto.SecretKey;
Import Javax.crypto.spec.IvParameterSpec;
Import Sun.misc.BASE64Decoder;
Import Sun.misc.BASE64Encoder;
JCE Application
public class Mainencrypt {
static String keyfile = "C:/key.xml";
Static Properties = GetProperties ();
Cipher Ecipher;
Cipher Dcipher;
Private final String Jdbcproperties_path = "Socket_jdbc.properties";
/**
* Generate key.
*
*/
public static void Savedeskey () {
try {
keyfile = Property.getproperty ("KeyFile");
securerandom sr = new SecureRandom ();
//generates a Keygenerator object for the DES algorithm we choose
keygenerator kg = Keygenerator.getinstance ("DES");
kg.init (SR);
fileoutputstream fos = new FileOutputStream (keyfile);
objectoutputstream oos = new ObjectOutputStream (FOS);
//generate key
secretkey key = Kg.generatekey ();
oos.writeobject