|
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.pheox.jcapi.JCAPIUtil
public final class JCAPIUtil
Utility functions not directly related to the functionality of the JCE framework are available through this class.
To learn more about how this class can be used, please look at the following example
programs that can be found in JCAPI's examples directory, by default located in
C:\<application data directory>\JCAPI\examples:
util\CertStores.javautil\EnvironmentInfo.javautil\ListSupportedAlgorithms.javautil\StringUtils.java
| Field Summary | |
|---|---|
static int |
ALG_CLASS_ALL
MS CAPI algorithm class known by JCAPI. |
static int |
ALG_CLASS_ANY
MS CAPI algorithm class known by JCAPI. |
static int |
ALG_CLASS_DATA_ENCRYPT
MS CAPI algorithm class known by JCAPI. |
static int |
ALG_CLASS_HASH
MS CAPI algorithm class known by JCAPI. |
static int |
ALG_CLASS_KEY_EXCHANGE
MS CAPI algorithm class known by JCAPI. |
static int |
ALG_CLASS_MSG_ENCRYPT
MS CAPI algorithm class known by JCAPI. |
static int |
ALG_CLASS_SIGNATURE
MS CAPI algorithm class known by JCAPI. |
static int |
KEY_USAGE_ENCRYPTION
Equals the MS CAPI key usage identity AT_KEYEXCHANGE. |
static int |
KEY_USAGE_SIGNATURE
Equals the MS CAPI key usage identity AT_SIGNATURE. |
| Method Summary | |
|---|---|
static java.lang.String |
asHex(byte[] buf)
Returns a hex decimal (base 16) string representation of the given byte array. |
static void |
createCertStore(java.lang.String name)
Creates a MS CAPI certificate/system store. |
static byte[] |
decodeBase64(java.lang.String buf)
Will decode the Base64 encoded string. |
static void |
deleteCertStore(java.lang.String name)
Will delete the MS CAPI certificate/system store given by parameter name. |
static java.lang.String |
encodeBase64(byte[] buf)
Will Base64 encode the given string. |
static int |
getAlgorithmClass(int algId)
Returns the algorithm class of the given algorithm identifier. |
static JCAPICSPAlgorithmKeyLengths |
getAlgorithmKeyLengths(JCAPICSPAlgorithm alg)
Returns the supported key lengths (minimum, maximum, and default lengths) for the given algorithm. |
static JCAPICSPAlgorithm[] |
getAlgorithmsByCSP(java.lang.String cspName)
Returns all algorithms that are supported by the Cryptographic Service Provider (CSP) given in cspName. |
static java.lang.String |
getCertificateFriendlyName(java.lang.String alias)
Returns the MS CAPI friendly name of the certificate referred by the given parameter alias. |
static java.lang.String |
getCertStoreFriendlyName(java.lang.String certStoreName)
Returns the friendly name of the MS CAPI certificate/system store given by parameter certStoreName. |
static java.lang.String[] |
getCertStoreNames()
Returns a list of all MS CAPI certificate stores (a.k.a system stores) available. |
static java.lang.String |
getCSP(java.lang.String alias)
Returns the name of the Cryptographic Service Provider (CSP) used for managing the certificate/key entry given by parameter alias. |
static java.lang.String[] |
getCSPs()
Returns a list of all available MS CAPI Cryptographic Service Providers (CSP) in your system. |
static java.lang.String |
getEnvironmentInfo()
Returns information about the environment in which JCAPI is executed. |
static java.lang.String |
getJCAPIDLLVersion()
Returns the version of the JCAPI DLL that is used by this particular version of JCAPI. |
static java.lang.String |
getJCAPILicense()
Returns the license agreement for this particular copy of JCAPI. |
static java.lang.String |
getJCAPIVersion()
Returns the version of JCAPI. |
static int |
getPrivateKeyUsage(java.lang.String alias)
Returns the key usage of the key entry given by parameter alias. |
static int |
getProviderTypeByAlias(java.lang.String alias)
Returns the provider type of the JCAPI certificate alias given in parameter alias. |
static int |
getProviderTypeByCSP(java.lang.String csp)
Returns the provider type of the Cryptographic Service Provider (CSP) name given in parameter csp. |
static boolean |
isCertStoreAvailable(java.lang.String store)
Returns true if the given MS CAPI certificate/system
store exists, else false. |
static boolean |
isCSPAvailable(java.lang.String csp)
Returns true if the Cryptographic Service Provider (CSP)
given in parameter csp can be found and used in MS CAPI,
else false. |
static void |
setCertificateFriendlyName(java.lang.String alias,
java.lang.String friendlyName)
Set friendly name friendlyName for the certificate
referred by the given parameter alias. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int ALG_CLASS_ANY
public static final int ALG_CLASS_SIGNATURE
public static final int ALG_CLASS_MSG_ENCRYPT
public static final int ALG_CLASS_DATA_ENCRYPT
public static final int ALG_CLASS_HASH
public static final int ALG_CLASS_KEY_EXCHANGE
public static final int ALG_CLASS_ALL
public static final int KEY_USAGE_ENCRYPTION
public static final int KEY_USAGE_SIGNATURE
| Method Detail |
|---|
public static java.lang.String getJCAPIVersion()
public static java.lang.String getJCAPIDLLVersion()
JCAPIJNIRuntimeException - if an unexpected error occur inside MS CAPI.public static java.lang.String getEnvironmentInfo()
JCAPIJNIRuntimeException - if an unexpected error occur inside MS CAPI.public static java.lang.String getJCAPILicense()
public static java.lang.String[] getCSPs()
JCAPIJNIRuntimeException - if an unexpected error occur in MS CAPI.
public static java.lang.String getCSP(java.lang.String alias)
throws JCAPIUnknownAliasException,
java.lang.IllegalArgumentException
alias.
alias - the JCAPI alias of the certificate/key entry.
JCAPIUnknownAliasException - if given alias does not exist.
java.lang.IllegalArgumentException - if parameter alias is
null or empty.
JCAPIJNIRuntimeException - if an unexpected error occur inside MS CAPI.
public static boolean isCSPAvailable(java.lang.String csp)
throws java.lang.IllegalArgumentException
true if the Cryptographic Service Provider (CSP)
given in parameter csp can be found and used in MS CAPI,
else false.
For example, the following CSP is present on all Windows
systems, and this method will thus always return true
in this case:
JCAPIUtil.isCSPAvailable("Microsoft Base Cryptographic Provider v1.0");
Hint: you can get a list of all available CSPs through the following
method getCSPs().
csp - the csp to check for.
true if the CSP can be found, else false.
java.lang.IllegalArgumentException - if parameter csp is
null or empty.public static java.lang.String[] getCertStoreNames()
JCAPIKeyStore.
JCAPI uses the ADDRESSBOOK store as its default certificate entry store. If this store does not exist (which is usually the case if Outlook has not been installed and configured yet) then JCAPI will automatically create the ADDRESSBOOK store during start up.
JCAPI will by default access all certificate stores available
e.g. when method aliases() in class java.security.KeyStore
is called, then an enumeration of certificates found in all these
stores are returned.
If you want JCAPI to access a different set of certificate stores, then
use the JCAPI dynamic key store feature, see method
JCAPICryptoFactory.createKeyStoreInstance(String,String,String[],String,String,String,String,String,boolean).
JCAPIJNIRuntimeException - if an unexpected error occur in MS CAPI.
public static boolean isCertStoreAvailable(java.lang.String store)
throws java.lang.IllegalArgumentException
true if the given MS CAPI certificate/system
store exists, else false.
store - the MS CAPI certificate/system store to check for.
true if the store can be found, else false.
java.lang.IllegalArgumentException - if parameter store is
null or empty.
public static java.lang.String getCertificateFriendlyName(java.lang.String alias)
throws JCAPIUnknownAliasException,
java.lang.IllegalArgumentException
alias.
alias - the certificate alias.
null if
no friendly name is defined for alias.
JCAPIUnknownAliasException - if given alias does not exist.
java.lang.IllegalArgumentException - if parameter alias is
null or empty.
JCAPIJNIRuntimeException - if an unexpected error occur in JCAPI DLL.
public static void setCertificateFriendlyName(java.lang.String alias,
java.lang.String friendlyName)
throws java.lang.IllegalArgumentException,
JCAPIUnknownAliasException
friendlyName for the certificate
referred by the given parameter alias.
alias - The certificate alias.friendlyName - The certificate friendly name.
java.lang.IllegalArgumentException - if parameter alias is
null or empty, or if parameter
friendlyName is null.
JCAPIUnknownAliasException - if the given alias does not exist.
JCAPIJNIRuntimeException - if an unexpected error occur in JCAPI DLL.
public static java.lang.String getCertStoreFriendlyName(java.lang.String certStoreName)
throws java.lang.IllegalArgumentException,
JCAPIJNIRuntimeException
certStoreName.My in the
certStoreName parameter, then the string
Personal is returned when you are using an English
version of your Windows operating system.
Hint: use method getCertStoreNames()
to get a list of all existing MS CAPI certificate/system stores.
certStoreName - The name of a MS CAPI certificate/system store.
null if certStoreName does not
exist or if no friendly name is defined for
certStoreName.
java.lang.IllegalArgumentException - if parameter certStoreName
is null or empty,
JCAPIJNIRuntimeException - if an unexpected error occur in JCAPI DLL.
public static int getPrivateKeyUsage(java.lang.String alias)
throws java.lang.IllegalArgumentException,
java.security.InvalidKeyException,
JCAPIUnknownAliasException,
JCAPIJNIRuntimeException
alias.
Possible return values are:
The key usage will tell you the primary purpose of using that
particular private key. It is common to use one private key for
signing, and another private key for encryption/wrapping. In
MS CAPI this is also known as AT_SIGNATURE and AT_KEYEXCHANGE.
Some CSPs don't allow a signing key to be used for encryption, and
vice versa.
alias - the JCAPI alias of the key entry to check.
java.lang.IllegalArgumentException - if alias is null or empty.
java.security.InvalidKeyException - if alias doesn't refer to a key entry
i.e. it has no private key.
JCAPIUnknownAliasException - if the alias doesn't exist.
JCAPIJNIRuntimeException - if an unexpected error occur in JCAPI DLL.
public static void createCertStore(java.lang.String name)
throws java.lang.IllegalArgumentException
name - the name of a MS CAPI certificate/system store to be created.
Cannot be null or empty.
java.lang.IllegalArgumentException - if parameter name
is null or empty.
JCAPIJNIRuntimeException - if the store cannot be created.
public static void deleteCertStore(java.lang.String name)
throws java.lang.IllegalArgumentException
name.
Hint: use method getCertStoreNames()
to get a list of all existing MS CAPI certificate/system stores.
name - the name of a MS CAPI certificate/system store to be deleted.
Cannot be null or empty.
java.lang.IllegalArgumentException - if parameter name
is null or empty.
JCAPIJNIRuntimeException - if the store cannot be deleted e.g. if
it does not exist.
public static JCAPICSPAlgorithm[] getAlgorithmsByCSP(java.lang.String cspName)
throws java.security.NoSuchProviderException,
java.lang.IllegalArgumentException
cspName.
cspName - the name of the Cryptographic Service Provider (CSP).
JCAPICSPAlgorithm instances, or an empty array
if no supported algorithms are found.
java.security.NoSuchProviderException - if cspName is not a
known/registered MS CAPI Cryptographic Service Provider.
java.lang.IllegalArgumentException - if parameter cspName
is null or empty.
JCAPIJNIRuntimeException - if MS CAPI fails to enumerate the supported algorithms.
public static JCAPICSPAlgorithmKeyLengths getAlgorithmKeyLengths(JCAPICSPAlgorithm alg)
throws java.security.NoSuchProviderException,
java.lang.IllegalArgumentException
alg - the MS CAPI CSP supported algorithm.
JCAPICSPAlgorithmKeyLengths instance containing key length info,
or null if no info could be found.
java.security.NoSuchProviderException - if the alg instance holds a non-existing provider.
java.lang.IllegalArgumentException - if parameter alg is null.
JCAPIJNIRuntimeException - if MS CAPI fails to get the key lengths for the given algorithm.public static int getAlgorithmClass(int algId)
The algorithm classes known by JCAPI are:
ALG_CLASS_ANYALG_CLASS_SIGNATUREALG_CLASS_MSG_ENCRYPTALG_CLASS_DATA_ENCRYPTALG_CLASS_HASHALG_CLASS_KEY_EXCHANGEALG_CLASS_ALL
algId - the algorithm identifier.
public static int getProviderTypeByAlias(java.lang.String alias)
throws java.lang.IllegalArgumentException
alias.
alias - The JCAPI certificate alias to get the provider type for.
0 if the alias doesn't exist.
java.lang.IllegalArgumentException - if alias is null or empty.
JCAPIJNIRuntimeException - if an unexpected error occur in MS CAPI.
public static int getProviderTypeByCSP(java.lang.String csp)
throws java.lang.IllegalArgumentException,
java.security.NoSuchProviderException
csp.
csp - The MS CAPI CSP name to get the provider type for.
java.lang.IllegalArgumentException - if csp is null or empty.
java.security.NoSuchProviderException - if the given CSP doesn't exist.
JCAPIJNIRuntimeException - if an unexpected error occur in MS CAPI.public static java.lang.String encodeBase64(byte[] buf)
buf - the string to Base64 encode.
public static byte[] decodeBase64(java.lang.String buf)
buf - the Base64 encoded string to decode.
public static java.lang.String asHex(byte[] buf)
buf - an array of bytes to convert to a hex decimal string.
|
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||