Пример #1
0
        IKey IKms.GetNewKey()
        {
            IKey key = new IKeyImpl();

            key.Name = "Key " + _Keys.Count.ToString();
            return(key);
        }
Пример #2
0
        protected virtual bool LoadKeysFile(XmlDocument doc)
        {
            bool result = false;

            _Keys.Clear();
            _Keyrings.Clear();

            //XmlDocument doc = new XmlDocument();
            try
            {
                //doc.Load(keysFile);

                XmlNode root     = doc.DocumentElement;
                XmlNode keys     = root["keys"];
                XmlNode keyrings = root["keyrings"];

                if (keys != null)
                {
                    foreach (XmlNode node in keys)
                    {
                        IKey key = new IKeyImpl(node);

                        _Keys.Add(key);
                    } //foreach (XmlNode node in keys)
                }
                if (keyrings != null)
                {
                    foreach (XmlNode node in keyrings)
                    {
                        IKeyring keyring = new IKeyringImpl(node);

                        _Keyrings.Add(keyring);
                    } //foreach (XmlNode node in keyrings)
                }
                result = true;
            }
            catch (Exception exc)
            {
                log.Debug(exc.ToString());
            }

            return(result);
        } //protected virtual bool LoadKeysFile(string keysFile)
Пример #3
0
        IKey IKey.DeriveKey(byte[] derivationData, KeyChaining chaining)
        {
            IKey result = null;

            if (Initialized)
            {
                byte[] derivedKey = null;
                switch (_KeyType)
                {
                case keyType.DESede:
                    derivedKey = encryptDesEde(derivationData, chaining);
                    break;

                case keyType.AES:
                    derivedKey = encryptAES(derivationData, chaining);
                    break;
                } //switch(_KeyType)

                if (derivedKey != null && derivedKey.Length == _Length)
                {
                    result = new IKeyImpl();

                    result.Name    = "Derived from " + _Name;
                    result.Purpose = _Purpose;
                    result.Subject = _Subject;
                    result.Scope   = _Scope;

                    result.keyType     = _KeyType;
                    result.Length      = _Length;
                    result.KeyChaining = _KeyChaining;

                    result.keyValue = Hex.ToHexString(derivedKey);
                    result.kcv      = Hex.ToHexString(result.Encrypt(Hex.Decode("000000")));
                } //if (derivedKey != null && derivedKey.Length == theKey.Length)
            }     //if (Initialized)

            return(result);
        } //IKey IKey.DeriveKey( ...