com.prosysopc.ua
Class SecureIdentity

java.lang.Object
  extended by com.prosysopc.ua.SecureIdentity
Direct Known Subclasses:
ApplicationIdentity, UserIdentity

public class SecureIdentity
extends Object


Field Summary
protected  org.opcfoundation.ua.transport.security.Cert certificate
           
protected  org.opcfoundation.ua.transport.security.PrivKey privateKey
           
 
Constructor Summary
protected SecureIdentity()
           
  SecureIdentity(org.opcfoundation.ua.transport.security.Cert certificate, org.opcfoundation.ua.transport.security.PrivKey privateKey)
          Create a new identity
  SecureIdentity(File certificateFile, File privateKeyFile, String privateKeyPassword)
          Create a new identity by loading the certificate and private key from files.
  SecureIdentity(File storeLocation, String alias, String privateKeyPassword, String keyStorePassword, String keyStoreType)
          Creates a new SecureIdentity object from a pfx-keystore file.
  SecureIdentity(URL certificateFile, URL privateKeyFile, String privateKeyPassword)
          Create a new identity by loading the certificate and private key from files.
 
Method Summary
protected  byte[] decrypt(org.opcfoundation.ua.transport.security.SecurityAlgorithm algorithm, byte[] dataToDecrypt, org.opcfoundation.ua.transport.security.PrivKey privKey)
          Decrypt data using the provided securityPolicy.
 byte[] decrypt(org.opcfoundation.ua.transport.security.SecurityPolicy securityPolicy, byte[] dataToDecrypt)
          Decrypt data using the provided securityPolicy.
 byte[] encrypt(org.opcfoundation.ua.transport.security.SecurityPolicy securityPolicy, byte[] dataToEncrypt)
          Encrypt data using the provided securityPolicy.
 boolean equals(Object obj)
           
 org.opcfoundation.ua.transport.security.Cert getCertificate()
           
 org.opcfoundation.ua.transport.security.KeyPair getKeys()
           
 org.opcfoundation.ua.transport.security.PrivKey getPrivateKey()
           
 int hashCode()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

certificate

protected org.opcfoundation.ua.transport.security.Cert certificate

privateKey

protected final org.opcfoundation.ua.transport.security.PrivKey privateKey
Constructor Detail

SecureIdentity

public SecureIdentity(org.opcfoundation.ua.transport.security.Cert certificate,
                      org.opcfoundation.ua.transport.security.PrivKey privateKey)
Create a new identity

Parameters:
certificate - The public key certificate
privateKey - The private key (optional)

SecureIdentity

public SecureIdentity(File certificateFile,
                      File privateKeyFile,
                      String privateKeyPassword)
               throws IOException,
                      SecureIdentityException
Create a new identity by loading the certificate and private key from files.

Parameters:
certificateFile - The certificate file.
privateKeyFile - The private key file.
privateKeyPassword - The password protecting the private key.
Throws:
IOException - If the files are not valid.
SecureIdentityException - if the certificate or private key file is not valid

SecureIdentity

public SecureIdentity(File storeLocation,
                      String alias,
                      String privateKeyPassword,
                      String keyStorePassword,
                      String keyStoreType)
               throws IOException,
                      SecureIdentityException
Creates a new SecureIdentity object from a pfx-keystore file.

Parameters:
storeLocation - location of the pfx-file
alias - string alias of the key pair, if null or not found in specified pfx-file, last entry is used
privateKeyPassword - password of the private key
keyStorePassword - password of the keystore
keyStoreType - type of the key store, "JKS" and "PKCS12" supported
Throws:
KeyStoreException - if the keystore has not been initialized (loaded)
NoSuchProviderException - if the specified provider (Bouncy Castle) is not registered in the security provider list
NoSuchAlgorithmException - if the algorithm used to check the integrity of the keystore cannot be found
CertificateException - if any of the certificates in the keystore could not be loaded
IOException
UnrecoverableKeyException - if a key in the keystore cannot be recovered
SecureIdentityException

SecureIdentity

public SecureIdentity(URL certificateFile,
                      URL privateKeyFile,
                      String privateKeyPassword)
               throws IOException,
                      SecureIdentityException
Create a new identity by loading the certificate and private key from files.

Parameters:
certificateFile - The certificate file.
privateKeyFile - The private key file.
privateKeyPassword - The password protecting the private key.
Throws:
IOException - If the files are not valid.
SecureIdentityException - if the certificate or private key file is not valid

SecureIdentity

protected SecureIdentity()
Method Detail

decrypt

public byte[] decrypt(org.opcfoundation.ua.transport.security.SecurityPolicy securityPolicy,
                      byte[] dataToDecrypt)
               throws SecureIdentityException
Decrypt data using the provided securityPolicy. The PrivateKey is used to decrypt, according to the specified policy.

Parameters:
securityPolicy - the security policy to use for the encryption.
dataToDecrypt - data to decrypt
Returns:
the decrypted data
Throws:
SecureIdentityException - if the decryption fails

encrypt

public byte[] encrypt(org.opcfoundation.ua.transport.security.SecurityPolicy securityPolicy,
                      byte[] dataToEncrypt)
               throws SecureIdentityException
Encrypt data using the provided securityPolicy. The Certificate is used to encrypt, according to the specified policy.

Parameters:
securityPolicy - the security policy to use for the encryption.
dataToEncrypt - data to encrypt
Returns:
the encrypted data
Throws:
SecureIdentityException - if the encryption fails

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getCertificate

public org.opcfoundation.ua.transport.security.Cert getCertificate()

getKeys

public org.opcfoundation.ua.transport.security.KeyPair getKeys()

getPrivateKey

public org.opcfoundation.ua.transport.security.PrivKey getPrivateKey()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

decrypt

protected byte[] decrypt(org.opcfoundation.ua.transport.security.SecurityAlgorithm algorithm,
                         byte[] dataToDecrypt,
                         org.opcfoundation.ua.transport.security.PrivKey privKey)
                  throws SecureIdentityException
Decrypt data using the provided securityPolicy. The PrivateKey is used to decrypt, according to the specified policy.

Parameters:
algorithm - the security policy to use for the encryption.
dataToDecrypt - data to decrypt
privKey - the private key to use
Returns:
the decrypted data
Throws:
SecureIdentityException - if the decryption fails


Copyright © 2018. All rights reserved.