Elexis API documentation
Version 2.1.6 as of December 11 2011

ch.rgw.crypt
Class JCECrypter

java.lang.Object
  extended by ch.rgw.crypt.JCECrypter
All Implemented Interfaces:
Cryptologist

public class JCECrypter
extends java.lang.Object
implements Cryptologist


Nested Class Summary
 
Nested classes/interfaces inherited from interface ch.rgw.crypt.Cryptologist
Cryptologist.SYMM_ALGOS, Cryptologist.VERIFY_RESULT
 
Field Summary
static short BLOWFISH_MARKER
           
static short DATA_MARKER
           
static short IV_MARKER
           
static short KEY_MARKER
           
static short MAGIC
           
static short VERSION
           
 
Constructor Summary
JCECrypter()
          Use this constructor if you only need symmetrical encryption/decryption
JCECrypter(java.lang.String keystore, char[] kspwd, java.lang.String mykey, char[] keypwd)
          Create a new Crypter.
 
Method Summary
 boolean addCertificate(byte[] certEncoded)
           
 boolean addCertificate(java.security.cert.X509Certificate cert)
           
 Result<byte[]> decrypt(byte[] encrypted)
          decrypt a byte array
 void decrypt(java.io.InputStream source, java.io.OutputStream dest)
           
 void decrypt(java.io.InputStream source, java.io.OutputStream dest, byte[] key)
          Decrypt a symmetrically encrypted stream
 byte[] encrypt(byte[] source, java.lang.String receiverKeyName)
          encrypt a byte array asymmetrically
 void encrypt(java.io.InputStream source, java.io.OutputStream dest, Cryptologist.SYMM_ALGOS algo, byte[] key)
          Encrypt a stream symmetrically with the provided key.
 void encrypt(java.io.InputStream source, java.io.OutputStream dest, java.lang.String receiverKeyName)
          enctrypt a Stream asymmetrically for the receiver
 void encryptBlowfish(java.io.InputStream plain, java.io.OutputStream encrypted, byte[] key)
           
 byte[] generateBlowfishKey()
           
 java.security.cert.X509Certificate generateCertificate(java.security.PublicKey pk, java.lang.String alias, TimeTool validFrom, TimeTool validUntil)
           
 java.security.KeyPair generateKeys(java.lang.String alias, char[] keypwd, TimeTool validFrom, TimeTool validUntil)
           
 java.security.cert.X509Certificate getCertificate(java.lang.String alias)
           
 byte[] getCertificateEncoded(java.lang.String alias)
           
 java.lang.String getUser()
           
 boolean hasCertificateOf(java.lang.String alias)
           
 boolean hasKeyOf(java.lang.String alias)
           
 boolean isFunctional()
           
 boolean removeCertificate(java.lang.String alias)
           
 byte[] sign(byte[] source)
          Sign a byte array (create and sign a MAC)
 Cryptologist.VERIFY_RESULT verify(byte[] data, byte[] signature, java.lang.String signerKeyName)
          Verify a MAC
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static short VERSION

MAGIC

public static short MAGIC

KEY_MARKER

public static short KEY_MARKER

IV_MARKER

public static short IV_MARKER

DATA_MARKER

public static short DATA_MARKER

BLOWFISH_MARKER

public static short BLOWFISH_MARKER
Constructor Detail

JCECrypter

public JCECrypter(java.lang.String keystore,
                  char[] kspwd,
                  java.lang.String mykey,
                  char[] keypwd)
           throws java.lang.Exception
Create a new Crypter. If the named keystore does not exist, it well created newly and a key for the named user will be created as well.

Parameters:
keystore - keystore to use or NULL for default keystore
kspwd - keystore password or NULL for default password
mykey - identifier for user's key in the named keystore
keypwd - password for the user's key
Throws:
java.lang.Exception

JCECrypter

public JCECrypter()
Use this constructor if you only need symmetrical encryption/decryption

Method Detail

decrypt

public Result<byte[]> decrypt(byte[] encrypted)
Description copied from interface: Cryptologist
decrypt a byte array

Specified by:
decrypt in interface Cryptologist
Parameters:
encrypted - the encrypted bytes
Returns:
the plain array or null of decryption failed

decrypt

public void decrypt(java.io.InputStream source,
                    java.io.OutputStream dest)
             throws CryptologistException
Specified by:
decrypt in interface Cryptologist
Throws:
CryptologistException

encrypt

public void encrypt(java.io.InputStream source,
                    java.io.OutputStream dest,
                    java.lang.String receiverKeyName)
             throws CryptologistException
Description copied from interface: Cryptologist
enctrypt a Stream asymmetrically for the receiver

Specified by:
encrypt in interface Cryptologist
Throws:
CryptologistException

encryptBlowfish

public void encryptBlowfish(java.io.InputStream plain,
                            java.io.OutputStream encrypted,
                            byte[] key)
                     throws CryptologistException
Throws:
CryptologistException

encrypt

public byte[] encrypt(byte[] source,
                      java.lang.String receiverKeyName)
Description copied from interface: Cryptologist
encrypt a byte array asymmetrically

Specified by:
encrypt in interface Cryptologist
Parameters:
source - the plain bytes
receiverKeyName - name of the receiver's public key
Returns:
the encrypted bytes or null if encryption failed

sign

public byte[] sign(byte[] source)
Description copied from interface: Cryptologist
Sign a byte array (create and sign a MAC)

Specified by:
sign in interface Cryptologist
Parameters:
source - the bytes to sign
Returns:
the signature

verify

public Cryptologist.VERIFY_RESULT verify(byte[] data,
                                         byte[] signature,
                                         java.lang.String signerKeyName)
Description copied from interface: Cryptologist
Verify a MAC

Specified by:
verify in interface Cryptologist
Parameters:
data - the signed data
signature - the signed digest
signerKeyName - name of the signer's public key
Returns:

hasCertificateOf

public boolean hasCertificateOf(java.lang.String alias)
Specified by:
hasCertificateOf in interface Cryptologist

hasKeyOf

public boolean hasKeyOf(java.lang.String alias)
Specified by:
hasKeyOf in interface Cryptologist

addCertificate

public boolean addCertificate(java.security.cert.X509Certificate cert)
Specified by:
addCertificate in interface Cryptologist

addCertificate

public boolean addCertificate(byte[] certEncoded)
Specified by:
addCertificate in interface Cryptologist

generateKeys

public java.security.KeyPair generateKeys(java.lang.String alias,
                                          char[] keypwd,
                                          TimeTool validFrom,
                                          TimeTool validUntil)
Specified by:
generateKeys in interface Cryptologist

generateCertificate

public java.security.cert.X509Certificate generateCertificate(java.security.PublicKey pk,
                                                              java.lang.String alias,
                                                              TimeTool validFrom,
                                                              TimeTool validUntil)
Specified by:
generateCertificate in interface Cryptologist

getUser

public java.lang.String getUser()
Specified by:
getUser in interface Cryptologist

generateBlowfishKey

public byte[] generateBlowfishKey()

getCertificate

public java.security.cert.X509Certificate getCertificate(java.lang.String alias)
Specified by:
getCertificate in interface Cryptologist

getCertificateEncoded

public byte[] getCertificateEncoded(java.lang.String alias)
                             throws CryptologistException
Specified by:
getCertificateEncoded in interface Cryptologist
Throws:
CryptologistException

isFunctional

public boolean isFunctional()
Specified by:
isFunctional in interface Cryptologist

removeCertificate

public boolean removeCertificate(java.lang.String alias)
Specified by:
removeCertificate in interface Cryptologist

encrypt

public void encrypt(java.io.InputStream source,
                    java.io.OutputStream dest,
                    Cryptologist.SYMM_ALGOS algo,
                    byte[] key)
             throws CryptologistException
Description copied from interface: Cryptologist
Encrypt a stream symmetrically with the provided key.

Specified by:
encrypt in interface Cryptologist
Parameters:
source - the unencrypte source
dest - the encrypted destination
algo - the algorithm to use
key - the key in byte-encoded format. Must match the algorithm
Throws:
CryptologistException

decrypt

public void decrypt(java.io.InputStream source,
                    java.io.OutputStream dest,
                    byte[] key)
             throws CryptologistException
Description copied from interface: Cryptologist
Decrypt a symmetrically encrypted stream

Specified by:
decrypt in interface Cryptologist
Parameters:
source - the encrypted origin
dest - the decrypted destination
key - the key to use (must be in approprioate format for encryption method. The Method will be read from the Stream header)
Throws:
CryptologistException

Elexis API documentation
Version 2.1.6 as of December 11 2011

Copyright 2005-2011 by Gerry Weirich, Elexis