Class FinSecureKey
Holds a RSA key pair and its attributes.
public class FinSecureKey
- Inheritance
-
FinSecureKey
- Inherited Members
Remarks
Every instance of the FinSecureKey is owned by a particular security media, represented by its IFinSecurityMedia implementation. Usually an instance of a FinSecureKey is obtained through the ObtainKey(FinContact, FinSecureKeyType, int, int) method of an IFinSecurityMedia implementation.
A FinSecureKey instance can hold a public/private key pair or just the public key. In the latter case, the private key can either be completely unknown, or is securely stored on the security media that owns this FinSecureKey instance.
Constructors
FinSecureKey()
Constructs a FinSecureKey instance without any RSA keys.
public FinSecureKey()
FinSecureKey(byte[], byte[])
Creates a new FinSecureKey instance.
public FinSecureKey(byte[] vbModulus, byte[] vbExponent)
Parameters
vbModulusbyte[]The common RSA modulus of the new key. Commonly known as the public key. Must not be
null. Use the parameterless constructor in order to create a FinSecureKey instance for non-RSA keys.vbExponentbyte[]Optionally, the private RSA exponent of the new key. Commonly known as the private key. May be
nullif this represents just the public RSA key.
Exceptions
- ArgumentNullException
The parameter vbModulus is
null.- ArgumentOutOfRangeException
The parameter nKeyLength is outside of the allowed range.
- ArgumentException
The length of vbModulus or vbExponent is zero, or the significant length of vbModulus or vbExponent is greater than nKeyLength.
Fields
DEFAULTKEYLENGTH
The default key length.
public const int DEFAULTKEYLENGTH = 96
Field Value
MAXKEYLENGTH
The maximum key byte length that is supported is 512 bytes. This is also the maximum length of the corresponding key blobs in HBCI and FinTS segments.
public const int MAXKEYLENGTH = 512
Field Value
MINKEYLENGTH
The minimum key byte length that is allowed is arbitrarily chosen as 32 bytes by this constant. Actually valid HBCI RSA keys currently must not be shorter than 88 bytes with a minimum nominal length of 96 bytes.
public const int MINKEYLENGTH = 32
Field Value
Properties
BankCode
The bank code of the key name.
public string BankCode { get; set; }
Property Value
CID
Optional CID that shall be used with this key. If null, then no CID will be
used.
public byte[] CID { get; set; }
Property Value
- byte[]
Certificate
Optional certificate associated with this key. If null, then no certificate
is available for this key.
public byte[] Certificate { get; set; }
Property Value
- byte[]
CertificateType
The type of certificate associated with this key.
public int CertificateType { get; set; }
Property Value
CountryCode
The country code of the key name.
public string CountryCode { get; set; }
Property Value
IsPrivateRSA
Indicates whether this is a software RSA key pair with private key.
public bool IsPrivateRSA { get; }
Property Value
IsRSA
Indicates whether this is a software RSA key.
public bool IsRSA { get; }
Property Value
Remarks
This is true when this FinSecureKey is a software RSA key with at least the
public key part. Use IsPrivateRSA in order to determine whether this
is a software RSA key pair that includes the private and public key.
KeyID
The key identification that uniquely identifies the key on its security media.
public int KeyID { get; set; }
Property Value
Remarks
The KeyID is assigned by the IFinSecurityMedia implementation and should be of no meaning to application code, other than to reference that key.
KeyLength
The nominal byte length of the RSA keys.
public int KeyLength { get; }
Property Value
Remarks
For classic HBCI this is 96, even if the actual RSA key may be shorter. For longer RSA keys, this equals the number of bytes in the modulus. The value is always in the range from 96 to MAXKEYLENGTH. If this is not a RSA key, then the value is zero.
KeyNumber
The key number in the range from zero through 998.
public int KeyNumber { get; set; }
Property Value
- int
The value 999 is reserved to designate the current key number, regardless of its value, and therefore cannot be explicitly assigned to any key.
KeyState
The current state of this key.
public FinSecureKeyState KeyState { get; set; }
Property Value
KeyType
The type of this key.
public FinSecureKeyType KeyType { get; set; }
Property Value
KeyTypeLetter
The key type expressed as a single letter according to HBCI.
public string KeyTypeLetter { get; }
Property Value
KeyVersion
The key version in the range from zero through 998.
public int KeyVersion { get; set; }
Property Value
- int
The value 999 is reserved to designate the highest key version, regardless of its value, and therefore cannot be explicitly assigned to any key.
SignatureID
Optional signature counter associated with this key. If -1, then the signature counter is not maintained with the key, but rather must be maintained externally, e.g. in the FinContact instance.
public long SignatureID { get; set; }
Property Value
UserID
The user ID of the key name.
public string UserID { get; set; }
Property Value
Methods
Clone()
Creates a new deep copy of this FinSecureKey instance.
public FinSecureKey Clone()
Returns
ComputeFingerprint(FinHash)
Computes the hash value over the public key which is used in the Ini-Letter and is also stored on ZKA SECCOS cards.
public byte[] ComputeFingerprint(FinHash nHash)
Parameters
nHashFinHashNEW: The desired hash algorithm for computing the fingerprint must be provided. This used to be RIPEMD-160 in all cases, but may now also be SHA-256 in some cases.
Returns
- byte[]
Exceptions
- InvalidOperationException
This is not a RSA key (see IsRSA).
Decrypt(FinOperationMode, byte[])
Decrypt data using the private RSA value of this FinSecureKey.
public byte[] Decrypt(FinOperationMode nOpMode, byte[] vbCrypt)
Parameters
nOpModeFinOperationModeThe cryptographic operation mode that shall be applied.
vbCryptbyte[]
Returns
- byte[]
Exceptions
- InvalidOperationException
This is not a RSA key pair (see IsPrivateRSA).
Encrypt(FinOperationMode, byte[])
Encrypt data using the public RSA value of this FinSecureKey.
public byte[] Encrypt(FinOperationMode nOpMode, byte[] vbData)
Parameters
nOpModeFinOperationModeThe cryptographic operation mode that shall be applied.
vbDatabyte[]
Returns
- byte[]
Exceptions
- InvalidOperationException
This is not a RSA key (see IsRSA).
Generate(int)
Generates a new RSA key pair of the given length.
public static FinSecureKey Generate(int nKeyLength)
Parameters
nKeyLengthintByte length of the RSA keys to be generated. This must be in the range from MINKEYLENGTH to MAXKEYLENGTH.
Returns
GenerateHIISA(int, FinOperationMode)
public FinSegment GenerateHIISA(int nSegmentVersion, FinOperationMode nOpMode)
Parameters
nSegmentVersionintnOpModeFinOperationMode
Returns
GetPublicExponent()
Provides the public RSA exponent (which is always Fermat 4) as a byte array.
public byte[] GetPublicExponent()
Returns
- byte[]
The public exponent or
nullif this is not a software RSA key.
GetPublicExponent(byte[], int, int)
Provides the public RSA exponent (which is always Fermat 4) as a byte array.
public void GetPublicExponent(byte[] vbBuffer, int nOffset, int nLength)
Parameters
Remarks
If this is not a software RSA key, then the destination bytes of the byte array are cleared.
Exceptions
- ArgumentNullException
The parameter vbBuffer was
null.- ArgumentOutOfRangeException
The parameter nOffset or nLength was invalid.
GetPublicModulus()
Provides the common public RSA modulus as a byte array.
public byte[] GetPublicModulus()
Returns
- byte[]
Returns a compact byte array that contains only the significant bytes of the public modulus. If this is not a software RSA key, then
nullis returned.
GetPublicModulus(byte[], int, int)
Provides the common public RSA modulus as a byte array.
public void GetPublicModulus(byte[] vbBuffer, int nOffset, int nLength)
Parameters
Remarks
If this is not a software RSA key, then the destination bytes of the byte array are cleared.
Exceptions
- ArgumentNullException
The parameter vbBuffer was
null.- ArgumentOutOfRangeException
The parameter nOffset or nLength was invalid.
ParseHIISA(FinSegment)
Creates a new FinSecureKey instance from a given HIISA segment.
public static FinSecureKey ParseHIISA(FinSegment aHIISA)
Parameters
aHIISAFinSegment
Returns
SignHash(FinOperationMode, FinHash, byte[])
Sign hash value using the private RSA value of this FinSecureKey.
public byte[] SignHash(FinOperationMode nOpMode, FinHash nHash, byte[] vbHash)
Parameters
nOpModeFinOperationModeThe cryptographic operation mode that shall be applied.
nHashFinHashIdentifies the hash algorithm that was used to produce the hash value. This is neeed for properly formatting the hash value for the signature operation.
vbHashbyte[]
Returns
- byte[]
Exceptions
- InvalidOperationException
This is not a RSA key pair (see IsPrivateRSA).
Verify(FinOperationMode, FinHash, byte[], byte[])
Verify hash value using the public RSA value of this FinSecureKey.
public bool Verify(FinOperationMode nOpMode, FinHash nHash, byte[] vbHash, byte[] vbSignature)
Parameters
nOpModeFinOperationModeThe cryptographic operation mode that shall be applied.
nHashFinHashIdentifies the hash algorithm that was used to produce the hash value. This is neeed for properly formatting the hash value for the verify operation.
vbHashbyte[]vbSignaturebyte[]
Returns
Exceptions
- InvalidOperationException
This is not a RSA key (see IsRSA).