JDK Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.32, 2006

JCA - Key Factory - Encoding Tool

Part:   1   2  3 

JDK Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Internationalization

Character Set and Encoding

Socket Communication

Document Object Model (DOM)

XSD Validation in Java

XSL - Transformer in Java

JCA - Private and Public Key Pairs

JCE - Secret Key

SSL (Secure Socket Layer)

SSL - Client Authentication

... Table of Contents

This chapter describes some parts of the JCA (Java Cryptography Architecture) which has been included in JDK since 1.1:

  • What is key encoding?
  • Key factory class and encoded key specification classes.
  • A sample program to show you how to read in private and public key pairs.

What is Key Encoding?

Key encoding is the process of converting an encryption or decryption key into a specific encoding format for storing and transmitting.

JDK offers a group of classes to support key encoding:

  • KeyFactory - A class to convert keys between Key objects and EncodedKeySpec objects.
  • EncodedKeySpec - An abstract class offers a grouping point of all sub classes that represent various key encoding standards.
  • PKCS8EncodedKeySpec - A sub class of EncodedKeySpec represents the ASN.1 encoding of a private key based PKCS#8 standard.
  • X509EncodedKeySpec - A sub class of EncodedKeySpec represents the ASN.1 encoding of a public key based on X.509 standard.

java.security.spec.PKCS8EncodedKeySpec Class

java.security.spec.PKCS8EncodedKeySpec - A sub class of EncodedKeySpec represents the ASN.1 encoding of a private key based PKCS#8 standard. It has three methods:

  • PKCS8EncodedKeySpec() - Constructs a PKCS8EncodedKeySpec object from the specified byte array that contains the PKCS#8 encoded private key.
  • getEncoded() - Returns the encoded key in a byte array of this object.
  • getFormat() - Returns the name of encoding used in this object.

java.security.spec.X509EncodedKeySpec Class

java.security.spec.X509EncodedKeySpec - A sub class of EncodedKeySpec represents the ASN.1 encoding of a private key based X.509 standard. It has three methods:

  • X509EncodedKeySpec() - Constructs a X509EncodedKeySpec object from the specified byte array that contains the X509 encoded public key.
  • getEncoded() - Returns the encoded key in a byte array of this object.
  • getFormat() - Returns the name of encoding used in this object.

java.security.KeyFactory Class

java.security.KeyFactory - A class to convert keys between Key objects and EncodedKeySpec objects. Major methods offered:

getInstance() - Returns a KeyFactory object of the specified algorithm and the specified security package provider. If not specified, the default security package provider will be used.

generatePrivate() - Generates a PrivateKey object based on the specified EncodedKeySpec object, and returns it.

generatePublic() - Generates a PublicKey object based on the specified EncodedKeySpec object, and returns it.

getKeySpec() - Converts a Key object to an EncodedKeySpec object, and returns it.

getAlgorithm() - Returns the algorithm name of this object.

getProvider() - Returns the provider as a provider object of this object.

(Continued on next part...)

Part:   1   2  3 

Dr. Herong Yang, updated in 2006
JDK Tutorials - Herong's Tutorial Notes - JCA - Key Factory - Encoding Tool