CXI
Loading...
Searching...
No Matches
Public Member Functions | List of all members
KeyBlob Class Reference

Constructs and parses key blobs of type 'Simple Blob', see Format of Key Blobs. More...

Inheritance diagram for KeyBlob:
[legend]
Collaboration diagram for KeyBlob:
[legend]

Public Member Functions

 KeyBlob (void)
 
 KeyBlob (ByteArray b)
 
 KeyBlob (const char *data, int len)
 
void setDES (const char *data, int len)
 
void setAES (const char *data, int len)
 
void setRSA (const char *mod, int l_mod, const char *pub, int l_pub, const char *p, int l_p, const char *q, int l_q, const char *dp, int l_dp, const char *dq, int l_dq, const char *u, int l_u, const char *prv, int l_prv)
 
void setRSA (const char *mod, int l_mod, const char *pub, int l_pub)
 
void setEC (const char *dp, int l_dp, const char *pub, int l_pub, const char *prv, int l_prv)
 
void setDSA (const char *p, int l_p, const char *q, int l_q, const char *g, int l_g, const char *pub, int l_pub, const char *prv, int l_prv)
 
ByteArray getProperty (int property) const
 
ByteArray getKeyComp (const char tag[]) const
 
ByteArray getPublic (void) const
 
ByteArray getPrivate (void) const
 
ByteArray getSecret (void) const
 
- Public Member Functions inherited from ByteArray
 ByteArray (void)
 
 ByteArray (int len)
 
 ByteArray (const char *data, int len)
 
 ByteArray (const char *str)
 
 ByteArray (int val, int len)
 
 ByteArray (const ByteArray &ba)
 
virtual ~ByteArray (void)
 
void clear (void)
 
int length (void) const
 
char * get (void)
 
const char * get (void) const
 
void set (const char *data, int len)
 
void append (const char *data, int len)
 
void append (const ByteArray &ba)
 
void insert (const char *data, int len, int offset)
 
void fill (char value, int len, int offset)
 
int getInt (int def_val=0) const
 
void setInt (int val, int len)
 
void appendInt (int val, int len)
 
void getString (char *str, int max_size) const
 
void setString (const char *str)
 
void appendString (const char *str)
 
std::string toString (void) const
 
std::string toHexString (void) const
 
int compare (const ByteArray &ba) const
 
ByteArray sub (int offset, int len=-1) const
 
ByteArray lstrip (void) const
 
ByteArray rstrip (const std::set< char > &charsToBeStripped) const
 
void read (const char *filename)
 
void write (const char *filename) const
 
void xtrace (const char *text=0) const
 
ByteArrayoperator= (const ByteArray &ba)
 
const ByteArrayoperator+= (const ByteArray &ba)
 
const ByteArrayoperator|= (const ByteArray &ba)
 
const ByteArrayoperator^= (const ByteArray &ba)
 
char & operator[] (int idx)
 

Detailed Description

Constructs and parses key blobs of type 'Simple Blob', see Format of Key Blobs.

Example:

The following example illustrates the usage of the KeyBlob class:

// create 128 Bit AES key blob
KeyBlob aesKeyBlob;
aesKeyKeyBlob.setAES("\x1\x2\x3\x4\x5\x6\x7\x8\x9\x0\xA\xB\xC\xD\xE\xF", 16);
// import key into CryptoServer
PropertyList keyTemplate;
keyTemplate.setName("AES key");
Key aesKey = cxi->key_import(CXI_KEY_FLAG_OVERWRITE,
keyTemplate,
aesKeyBlob,
NULL);
// use key ...
// open RSA key
keyTemplate.clear();
keyTemplate.setName("RSA key");
Key rsaKey = cxi->key_open(0, keyTemplate);
// export public RSA key
KeyBlob rsaKeyBlob = cxi->key_export(CXI_KEY_BLOB_SIMPLE|CXI_KEY_TYPE_PUBLIC, rsaKey, NULL, 0);
// dump components
rsaKeyBlob.getKeyComp("MO").xtrace("Modulus");
rsaKeyBlob.getKeyComp("PE").xtrace("Public Exponent");
void xtrace(const char *text=0) const
Definition: bytearray.cpp:611
Constructs and parses key blobs of type 'Simple Blob', see Format of Key Blobs.
Definition: sw/cxi_api_c/def/keyblob.h:19
void setAES(const char *data, int len)
Definition: keyblob.cpp:133
ByteArray getKeyComp(const char tag[]) const
Definition: keyblob.cpp:471
Encapsulates key handles or key blobs of type 'Backup Blob', see Format of Key Blobs.
Definition: sw/cxi_api_c/def/key.h:19
Constructs and parses key property lists, see Key Properties.
Definition: sw/cxi_api_c/def/propertylist.h:19
void setName(const char *name)
Definition: propertylist.cpp:510
void clear(void)
Definition: propertylist.cpp:226
#define CXI_KEY_BLOB_SIMPLE
Simple blob format (Utimaco)
Definition: fw/cxi/def/cxi_defs.h:288
#define CXI_KEY_TYPE_SECRET
Secrect key object.
Definition: fw/cxi/def/cxi_defs.h:271
#define CXI_KEY_TYPE_PUBLIC
Public key object.
Definition: fw/cxi/def/cxi_defs.h:267
Definition: cxi.cpp:173

Constructor & Destructor Documentation

◆ KeyBlob() [1/3]

KeyBlob ( void  )

Default Constructor, creates empty blob.

◆ KeyBlob() [2/3]

Copy Constructor, creates blob from given ByteArray.

◆ KeyBlob() [3/3]

KeyBlob ( const char *  data,
int  len 
)

Overloaded Constructor, creates blob vom given data.

Member Function Documentation

◆ setDES()

void setDES ( const char *  data,
int  len 
)

Creates a blob from the given DES key components.

Parameters
datapointer to key components
lenlength of key components in bytes [8,16,24]
Exceptions
cxi::Exceptionif length of key is not 8,16 or 24

◆ setAES()

void setAES ( const char *  data,
int  len 
)

Creates a blob from the given AES key components.

Parameters
datapointer to key components
lenlength of key components in bytes [16,24,32]
Exceptions
cxi::Exceptionif length of key is not 16,24 or 32

◆ setRSA() [1/2]

void setRSA ( const char *  mod,
int  l_mod,
const char *  pub,
int  l_pub,
const char *  p,
int  l_p,
const char *  q,
int  l_q,
const char *  dp,
int  l_dp,
const char *  dq,
int  l_dq,
const char *  u,
int  l_u,
const char *  prv,
int  l_prv 
)

Creates a blob from the given RSA key components

Parameters
modpointer to modulus
l_modlength of modulus
pubpointer to public exponent
l_publength of public exponent
ppointer to prime p (private key only)
l_plength of prime p
qpointer to prime q (private key only)
l_qlength of prime q
dppointer to dp (private key only)
l_dplength of dp
dqpointer to dq (private key only)
l_dqlength of dq
upointer to u (private key only)
l_ulength of u
prvpointer to private exponent (optional)
l_prvlength of private exponent
Exceptions
cxi::Exception

◆ setRSA() [2/2]

void setRSA ( const char *  mod,
int  l_mod,
const char *  pub,
int  l_pub 
)

Creates a blob from the given RSA key components

Parameters
modpointer to modulus
l_modlength of modulus
pubpointer to public exponent
l_publength of public exponent
Exceptions
cxi::Exception

◆ setEC()

void setEC ( const char *  dp,
int  l_dp,
const char *  pub,
int  l_pub,
const char *  prv,
int  l_prv 
)

Creates a blob from the given EC key components

Parameters
dppointer to domain parameter (curve name)
l_dplength of domain parameter
pubpointer to public key
l_publength of public key
prvpointer to private key (private key only)
l_prvlength of private key
Exceptions
cxi::Exception

◆ setDSA()

void setDSA ( const char *  p,
int  l_p,
const char *  q,
int  l_q,
const char *  g,
int  l_g,
const char *  pub,
int  l_pub,
const char *  prv,
int  l_prv 
)

Creates a blob from the given DSA key components

Parameters
ppointer to prime p
l_plength of prime p
qpointer to prime q
l_qlength of prime Q
gpointer to generator g
l_glength of generator g
pubpointer to public key
l_publength of public key
prvpointer to private key (private key only)
l_prvlength of private key
Exceptions
cxi::Exception

◆ getProperty()

ByteArray getProperty ( int  property) const

Returns the specified key property, see Key Properties.

Returns
property [byte array]
Exceptions
cxi::Exceptionif property can't be found or structure of blob is invalid

◆ getKeyComp()

ByteArray getKeyComp ( const char  tag[]) const

Returns the specified RSA key component. Public keys always contain the modulus ("MO") and public exponent ("PE"). Private keys contain either the secret exponent ("SE") or all CRT components ("P ", "Q", "DP", "DQ", "U ").

Parameters
tagkey component identifier ["MO", "PE", "P ", "Q", "DP", "DQ", "U ", "SE"]
Returns
key component [byte array]
Exceptions
cxi::Exceptionif component can't be found or structure of blob is invalid

◆ getPublic()

ByteArray getPublic ( void  ) const

Returns the public key value [DSA,EC].

Returns
public key [byte array]
Exceptions
cxi::Exceptionif component can't be found or structure of blob is invalid

◆ getPrivate()

ByteArray getPrivate ( void  ) const

Returns the private key value [DSA,EC].

Returns
private key [byte array]
Exceptions
cxi::Exceptionif component can't be found or structure of blob is invalid

◆ getSecret()

ByteArray getSecret ( void  ) const

Returns the secret key value [DES,AES].

Returns
secret key [byte array]
Exceptions
cxi::Exceptionif component can't be found or structure of blob is invalid