Core applications of the Java cryptographic Extension (JCE) framework

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.