Exemple #1
0
        ///<inheritdoc />
        public CryptoKey getSessionKey(int bits, TCryptoAlgo algorithm)
        {
            if (this.isSecure != true)
            {
                throw new ExceptionCryptoFailed("Session is not secure!");
            }

            //we only support AES
            if (algorithm != TCryptoAlgo.AES)
            {
                throw new ExceptionCryptoFailed("Unsupported algorithm requested.");
            }

            Array key;
            if (comCrypto.getSessionKey(handlePartner, out key) != 1)
            {
                throw new ExceptionCryptoFailed("Failed to get session key!");
            }

            if (key.Length * 8 != bits)
            {
                throw new ExceptionCryptoFailed("Key is of wrong bit-strength!");
            }

            return new CryptoKey((byte[])key, TCryptoAlgo.AES);
        }
Exemple #2
0
 /// <summary>
 /// The public constructor.
 /// </summary>
 /// <param name="rawKey">The raw key material.</param>
 /// <param name="algo">The cryptoggraphic algorithm the key is intended to be used with.</param>
 public CryptoKey(byte[] rawKey, TCryptoAlgo algo)
 {
     this.algo = algo;
     this.rawKey = rawKey;
 }