|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.opcfoundation.ua.utils.CryptoUtil
public class CryptoUtil
This is class contains Cryptographic utilities http://www.ietf.org/rfc/rfc2437.txt
| Constructor Summary | |
|---|---|
CryptoUtil()
|
|
| Method Summary | |
|---|---|
static byte[] |
asymmEncrypt(byte[] input,
Key key,
SecurityAlgorithm algorithm)
Deprecated. |
static byte[] |
base64Decode(String string)
base64Decode. |
static String |
base64Encode(byte[] bytes)
base64Encode a byte array to string |
static Mac |
createMac(SecurityAlgorithm algorithm,
byte[] secret)
Create Message Authentication Code (MAC) |
static ByteString |
createNonce(int bytes)
Create a non-repeatable set of bytes. |
static ByteString |
createNonce(SecurityAlgorithm algorithm)
createNonce. |
static void |
decryptAsymm(PrivateKey decryptingKey,
SecurityConfiguration profile,
byte[] dataToDecrypt,
byte[] output,
int outputOffset)
Convenience method for CryptoProvider.decryptAsymm(PrivateKey, SecurityAlgorithm, byte[], byte[], int)
Possible to use only SecurityConfiguration instead of specifying
SecurityAlgorithm explicitly. |
static byte[] |
encryptAsymm(byte[] input,
PublicKey key,
SecurityAlgorithm algorithm)
Convenience method for CryptoProvider.encryptAsymm(java.security.PublicKey, org.opcfoundation.ua.transport.security.SecurityAlgorithm, byte[], byte[], int). |
static void |
encryptAsymm(Certificate encryptingCertificate,
SecurityConfiguration profile,
byte[] dataToEncrypt,
byte[] output,
int outputOffset)
Convenience method for CryptoProvider.encryptAsymm(PublicKey, SecurityAlgorithm, byte[], byte[], int)
Possible to use only Certificate and SecurityConfiguration instead of
specifying PublicKey and SecurityAlgorithm explicitly. |
static String[] |
filterCipherSuiteList(String[] cipherSuiteSet,
String[] cipherSuitePatterns)
filterCipherSuiteList. |
static Cipher |
getAsymmetricCipher(SecurityAlgorithm algorithm)
Create signer instance using an algorithm uri. |
static int |
getAsymmInputBlockSize(SecurityAlgorithm algorithm)
getAsymmInputBlockSize. |
static int |
getCipherBlockSize(SecurityAlgorithm algorithm,
Key key)
Get cipher block (=output) size in bytes |
static String[] |
getCipherSuiteIntersection(String[] cipherSuiteSet1,
String[] cipherSuiteSet2,
boolean omitProtocol)
Create an intersection of two lists of cipher suite lists |
static CryptoProvider |
getCryptoProvider()
Getter for the field cryptoProvider. |
static int |
getNonceLength(SecurityAlgorithm algorithm)
Returns the length of the nonce to be used with an asymmetric or symmetric encryption algorithm. |
static int |
getPlainTextBlockSize(SecurityAlgorithm securityAlgorithm,
Key key)
Get plain text block (=input) size in bytes |
static SecureRandom |
getRandom()
Getter for the field random. |
static String |
getSecurityProviderName()
The Preferred Security Provider name. |
static String |
getSecurityProviderName(Class<?> class1)
Getter for the field securityProviderName. |
static int |
getSignatureSize(SecurityAlgorithm signatureAlgorithm,
Key key)
Get signature size in bytes |
static byte[] |
hexToBytes(String s)
hexToBytes. |
static void |
setCryptoProvider(CryptoProvider cryptoProvider)
Define the preferred CryptoProvider. |
static void |
setSecurityProviderName(String securityProviderName)
Define the preferred SecurityProvider. |
static SignatureData |
signAsymm(PrivateKey signerKey,
SecurityAlgorithm algorithm,
byte[] dataToSign)
signAsymm. |
static String |
toHex(byte[] bytes)
Convenience method for "displaying" a hex-string of a given byte array. |
static String |
toHex(byte[] bytes,
int bytesPerRow)
Convenience method for "displaying" a hex-string of a given byte array. |
static boolean |
verifyAsymm(X509Certificate certificate,
SecurityAlgorithm algorithm,
byte[] data,
byte[] signature)
Verify a signature. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CryptoUtil()
| Method Detail |
|---|
@Deprecated
public static byte[] asymmEncrypt(byte[] input,
Key key,
SecurityAlgorithm algorithm)
throws InvalidKeyException,
IllegalBlockSizeException,
BadPaddingException,
ServiceResultException,
NoSuchAlgorithmException,
NoSuchPaddingException
CryptoProvider.encryptAsymm(java.security.PublicKey, org.opcfoundation.ua.transport.security.SecurityAlgorithm, byte[], byte[], int). Deprecated: Use
encryptAsymm(byte[], java.security.PublicKey, org.opcfoundation.ua.transport.security.SecurityAlgorithm) instead.
input - an array of byte.key - a Key object.algorithm - a SecurityAlgorithm object.
InvalidKeyException - if any.
IllegalBlockSizeException - if any.
BadPaddingException - if any.
ServiceResultException - if any.
NoSuchAlgorithmException - if any.
NoSuchPaddingException - if any.public static byte[] base64Decode(String string)
base64Decode.
string - a String object.
public static String base64Encode(byte[] bytes)
base64Encode a byte array to string
bytes - the array of byte to convert.
String representing the byte array in base64 encoded string.
public static Mac createMac(SecurityAlgorithm algorithm,
byte[] secret)
throws ServiceResultException
algorithm - encryption algorithmsecret - an array of byte.
ServiceResultException - Bad_SecurityPolicyRejected algorithm not supportedpublic static ByteString createNonce(int bytes)
bytes - number of byte
public static ByteString createNonce(SecurityAlgorithm algorithm)
throws ServiceResultException
createNonce.
algorithm - a SecurityAlgorithm object.
ServiceResultException - if any.
public static void decryptAsymm(PrivateKey decryptingKey,
SecurityConfiguration profile,
byte[] dataToDecrypt,
byte[] output,
int outputOffset)
throws ServiceResultException
CryptoProvider.decryptAsymm(PrivateKey, SecurityAlgorithm, byte[], byte[], int)
Possible to use only SecurityConfiguration instead of specifying
SecurityAlgorithm explicitly.
decryptingKey - a PrivateKey object.profile - a SecurityConfiguration object.dataToDecrypt - an array of byte.output - outputoutputOffset - output offset
ServiceResultException - if any.
public static byte[] encryptAsymm(byte[] input,
PublicKey key,
SecurityAlgorithm algorithm)
throws InvalidKeyException,
IllegalBlockSizeException,
BadPaddingException,
ServiceResultException,
NoSuchAlgorithmException,
NoSuchPaddingException
CryptoProvider.encryptAsymm(java.security.PublicKey, org.opcfoundation.ua.transport.security.SecurityAlgorithm, byte[], byte[], int).
input - an array of byte.key - a PublicKey object.algorithm - a SecurityAlgorithm object.
InvalidKeyException - if any.
IllegalBlockSizeException - if any.
BadPaddingException - if any.
ServiceResultException - if any.
NoSuchAlgorithmException - if any.
NoSuchPaddingException - if any.
public static void encryptAsymm(Certificate encryptingCertificate,
SecurityConfiguration profile,
byte[] dataToEncrypt,
byte[] output,
int outputOffset)
throws ServiceResultException
CryptoProvider.encryptAsymm(PublicKey, SecurityAlgorithm, byte[], byte[], int)
Possible to use only Certificate and SecurityConfiguration instead of
specifying PublicKey and SecurityAlgorithm explicitly.
encryptingCertificate - Certificate which public key will be used during encryption.profile - Asymmetric encryption algorithm will be taken from this
SecurityConfigurationdataToEncrypt - Data to encryptoutput - outputoutputOffset - output offset
ServiceResultException - if any.
public static String[] filterCipherSuiteList(String[] cipherSuiteSet,
String[] cipherSuitePatterns)
filterCipherSuiteList.
cipherSuiteSet - an array of String objects.cipherSuitePatterns - an array of String objects.
String objects.
public static Cipher getAsymmetricCipher(SecurityAlgorithm algorithm)
throws ServiceResultException
algorithm - UA Specified algorithm
ServiceResultException - if algorithm is not supported by the stack
public static int getAsymmInputBlockSize(SecurityAlgorithm algorithm)
throws ServiceResultException
getAsymmInputBlockSize.
algorithm - a SecurityAlgorithm object.
ServiceResultException - if any.
public static int getCipherBlockSize(SecurityAlgorithm algorithm,
Key key)
throws ServiceResultException
algorithm - algorithmkey - Optional, required for asymmetric encryption algorithms
ServiceResultException - Bad_SecurityPolicyRejected algorithm not supported
public static String[] getCipherSuiteIntersection(String[] cipherSuiteSet1,
String[] cipherSuiteSet2,
boolean omitProtocol)
cipherSuiteSet1 - enabled cipher suitescipherSuiteSet2 - filter listomitProtocol - if true the first 3 characters are ignored in compare
public static CryptoProvider getCryptoProvider()
Getter for the field cryptoProvider.
CryptoProvider object.
public static int getNonceLength(SecurityAlgorithm algorithm)
throws ServiceResultException
For symmetric algorithms, returns the algorithm key size (in bytes). For asymmetric algorithms, returns 32.
algorithm - encryption algorithm or null (=no encryption)
ServiceResultException - Bad_SecurityPolicyRejected, if the algorithm is not supported
public static int getPlainTextBlockSize(SecurityAlgorithm securityAlgorithm,
Key key)
throws ServiceResultException
securityAlgorithm - algorithmkey - Optional, required for asymmetric encryption algorithms
ServiceResultException - Bad_SecurityPolicyRejected algorithm not supportedpublic static SecureRandom getRandom()
Getter for the field random.
public static String getSecurityProviderName()
RuntimeException - if none is available and none cannot be initialized.public static String getSecurityProviderName(Class<?> class1)
Getter for the field securityProviderName.
class1 - a Class object.
String object.
public static int getSignatureSize(SecurityAlgorithm signatureAlgorithm,
Key key)
throws ServiceResultException
signatureAlgorithm - a SecurityAlgorithm object.key - a Key object.
ServiceResultException - Bad_SecurityPolicyRejected algorithm not supportedpublic static byte[] hexToBytes(String s)
hexToBytes.
s - a String object.
public static void setCryptoProvider(CryptoProvider cryptoProvider)
cryptoProvider - the cryptoProvider to setpublic static void setSecurityProviderName(String securityProviderName)
securityProviderName - the securityProviderName to set, e.g. "BC" for
BouncyCastleProvider
public static SignatureData signAsymm(PrivateKey signerKey,
SecurityAlgorithm algorithm,
byte[] dataToSign)
throws ServiceResultException
signAsymm.
signerKey - the private key used to sign the dataalgorithm - asymmetric signer algorithm, See SecurityAlgorithmdataToSign - the data to sign
ServiceResultException - if the signing fails. Read the StatusCode and cause for more
detailspublic static String toHex(byte[] bytes)
toHex(byte[], int) with bytesPerRow=0 (no line breaks)
bytes - the byte array to "display"
String object.
public static String toHex(byte[] bytes,
int bytesPerRow)
bytes - the byte array to "display"bytesPerRow - number of bytes to include on a text row. If it is 0, no line
breaks are added.bytesPerRow - number of bytes to include on a text row. If it is 0, no line
breaks are added.
String object.
public static boolean verifyAsymm(X509Certificate certificate,
SecurityAlgorithm algorithm,
byte[] data,
byte[] signature)
throws ServiceResultException
certificate - the certificate used to verify the signaturealgorithm - the signature algorithmdata - data to verifysignature - the signature to verify
ServiceResultException - if the verification fails
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||