OpenCard  
 
OCF, the OpenCard Framework is a standard Java framework for working with Smart Cards.  
 

com.ibm.opencard.signature
Class MFC40KeyConverter

java.lang.Object
  |
  +--com.ibm.opencard.signature.MFC40KeyConverter
Direct Known Subclasses:
MFC421KeyConverter

public class MFC40KeyConverter
extends java.lang.Object
implements MFCKeyConverter

Create/read MFC 4.0 specific byte stream for PKA key files from opencard.opt.security key types.

Version:
$Id: MFC40KeyConverter.java,v 1.1 1999/12/02 16:06:08 damke Exp $

Constructor Summary
MFC40KeyConverter()
           
 
Method Summary
protected  java.math.BigInteger asBigInt(byte[] bytes, int offset, int len)
          Create BigInteger from PKA_FILE byte representation
 void assertSupportsKey(java.security.PrivateKey key)
          Check if the card can store a private key of the provided type
 void assertSupportsKey(java.security.PublicKey key)
          Check if the card can store a public key of the provided type
 byte[] fingerprint(int keyNr, int algid, byte hashID, byte keyUsage0, byte keyUsage1, byte paddingAlgorithm, byte[] pkaFile, boolean privateKey)
          Generate fingerprint as necessary for key validation.
 byte[] pkaFile(java.security.PrivateKey key, byte[] keyInfo)
          Create the MFC EF_PKA key file format specified for private key PKA files.
 byte[] pkaFile(java.security.PublicKey key, byte[] keyInfo)
          Create the MFC EF_PKA key file format specified for public key PKA files.
protected  byte[] pkaInt(java.math.BigInteger v, int n)
          Create byte[] representation of given BigInteger suitable for PKA files.
 java.security.PublicKey readPublicKey(MFCKeyInfo ki, byte[] fileContent)
          Construct a key from the key file content of an MFC key file Creates a subclass of java.security.PublicKey.
protected  byte[] unsign(byte[] data)
          Internal routine: Cope with stupid Java signed BigInteger arrays ^%$^&#%&@^*%#@
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MFC40KeyConverter

public MFC40KeyConverter()
Method Detail

asBigInt

protected java.math.BigInteger asBigInt(byte[] bytes,
                                        int offset,
                                        int len)
Create BigInteger from PKA_FILE byte representation

assertSupportsKey

public void assertSupportsKey(java.security.PrivateKey key)
                       throws java.security.InvalidKeyException
Check if the card can store a private key of the provided type
Specified by:
assertSupportsKey in interface MFCKeyConverter
Throws:
java.security.InvalidKeyException - The card does not support the kind of key provided.

assertSupportsKey

public void assertSupportsKey(java.security.PublicKey key)
                       throws java.security.InvalidKeyException
Check if the card can store a public key of the provided type
Specified by:
assertSupportsKey in interface MFCKeyConverter
Throws:
java.security.InvalidKeyException - key (sub)class not supported

fingerprint

public byte[] fingerprint(int keyNr,
                          int algid,
                          byte hashID,
                          byte keyUsage0,
                          byte keyUsage1,
                          byte paddingAlgorithm,
                          byte[] pkaFile,
                          boolean privateKey)
Generate fingerprint as necessary for key validation. Note: This method is not used by the signature service but can be used to test key validation with MFC 4.x cards. A key can be validated by providing a signature which was created signing the fingerprint of a key. To generate a fingerprint some bytes from the header of the EF_PKA file are needed as well as the complete content of the EF_PKA data in the format delivered by method pkaFile().
Parameters:
keyNr - number of key within directory scope
Returns:
fingerprint (byte array)

pkaFile

public byte[] pkaFile(java.security.PrivateKey key,
                      byte[] keyInfo)
               throws java.security.InvalidKeyException
Create the MFC EF_PKA key file format specified for private key PKA files.
Specified by:
pkaFile in interface MFCKeyConverter
Parameters:
keyInfo - Additional key info to be merged into actual key to make it a valid PKA file.
Returns:
Byte array in a form as specified for a full-fledged PKA file
Throws:
java.security.InvalidKeyException - The card does not support the kind of key provided

pkaFile

public byte[] pkaFile(java.security.PublicKey key,
                      byte[] keyInfo)
               throws java.security.InvalidKeyException
Create the MFC EF_PKA key file format specified for public key PKA files.
Specified by:
pkaFile in interface MFCKeyConverter
Parameters:
keyInfo - Additional key info to be merged into actual key to make it a valid PKA file.
Returns:
Byte array in a form as specified for a full-fledged PKA file
Throws:
java.security.InvalidKeyException - The card does not support the kind of key provided.

pkaInt

protected byte[] pkaInt(java.math.BigInteger v,
                        int n)
                 throws java.security.InvalidKeyException
Create byte[] representation of given BigInteger suitable for PKA files. The returned byte[]s will have exactly length n. (Zero-padded)
Throws:
java.security.InvalidKeyException - The card does not support the key strength.

readPublicKey

public java.security.PublicKey readPublicKey(MFCKeyInfo ki,
                                             byte[] fileContent)
                                      throws CardServiceException
Construct a key from the key file content of an MFC key file Creates a subclass of java.security.PublicKey.
Specified by:
readPublicKey in interface MFCKeyConverter
Throws:
CardServiceInabilityException - PKA algorithm not supported by card service

unsign

protected byte[] unsign(byte[] data)
Internal routine: Cope with stupid Java signed BigInteger arrays ^%$^&#%&@^*%#@
Parameters:
data - Byte array to be made 'unsigned'
Returns:
byte array that has a high probability of representing an unsigned BigInteger