Exporting all Versions of a Versioned Key
You can export the default version, a specific version, or all key versions.
To export all versions of a versioned key:
Call the
ExportKey
method of theNaeKeyManagement
class.Pass key name, a boolean, and KeyType. You can export both the symmetric and asymmetric keys.
For example:
NaeKeyManagement nkm = new NaeKeyManagement(session);
VersionedKey[] arrVerKeys = nkm.ExportKey("Example_Rijndael_key",true,NaeKeyManagement.KeyType.None);
Enum KeyType is defined as:
public enum KeyType
{
Public = 0,
PublicPrivate = 1,
None = 2
}
For symmetric keys, use KeyType.None
.
For asymmetric keys, use KeyType.Public
to get only the public key, and use KeyType.PublicPrivate
to get both the public and private components.
The return type of an ExportKey
is an array VersionedKey[]
. The VersionedKey
class consists of the following properties to store the key bytes of a particular version.
int Version;
byte[] KeyBytes;
Note
When a key has multiple versions and each version is used to encrypt the data; thereby creating multiple encrypted bytes.
When you decrypt the encrypted bytes and do not pass any version or pass the different version of the key in the request, then the version number is ignored, and the operation automatically identifies the key version from the header of the data.