Back to product page

PrivateKeyData property

Holds private key - as byte array.


An array of Byte values


  • Basic
object.PrivateKeyData(KeyType) [= value]
The PrivateKeyData(object,KeyType,value()) syntax has these parts:
objectAn expression evaluating to an object of type Keys.
KeyTypeRequired. A SSHKeyTypes enumeration, as described in settings. Type of the key.
value()An array of Byte values.


The settings for KeyType are:

Constant Value Description
RSAkey 0 Uses RSA key.
DSAkey 1 Uses DSA key.
ECDSAkey 2 Uses ECDSA key.

PrivateKeyData property is used if you don't want to call internal Load and Save methods to preserve key data between sessions. Once you Generate new key, you can retrieve it's raw data using this property (or PrivateKey property), and store it somewhere depending what your needs are. Obtaining private key data this way does not encrypt it in any way - you should do it by yourself when you store the key.

In later sessions, you can easily load your key internally, and put it in PrivateKeyData property and wodKeys will immediately be able to use it. KeyType must be specified to determine what key is stored/retrieved.

Note that setting PrivateKeyData with unexpected data may result in wodKeys rejecting your key. It is advised to set PrivateKeyData only with data you have previously retrieved from the same property (in previous session).

We have noticed that when MFC generates wrappers for wodKeys, it says it cannot generate wrapper for this member. Well, you should then just add it by yourself. In header file, add this line:

void GetPrivateKeyData(long KeyType, SAFEARRAY **result);
void SetPrivateKeyData(long KeyType, SAFEARRAY **DataArray);

and in wrapper implementation file, add this

void IKeys::GetPrivateKeyData(long KeyType, SAFEARRAY **result)
      VARIANT var;
      var.vt = VT_VARIANT;

      static BYTE parms[] = VTS_I4;
      InvokeHelper(0xc, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&var, parms, KeyType);

      *result = (SAFEARRAY *)var.punkVal;
void IKeys::SetPrivateKeyData(long KeyType, SAFEARRAY **DataArray)
      VARIANT var;
      var.vt = VT_UI1 | VT_ARRAY;
      var.parray = *DataArray;

      static BYTE parms[] = VTS_I4 VTS_VARIANT;
      InvokeHelper(0xc, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, KeyType, &var);