Ejemplo n.º 1
0
        //-----------------------------------------------------------------------------------------------------------------------------
        //
        //-----------------------------------------------------------------------------------------------------------------------------
        private Cryption GetCryptor(string crypto_key = "")
        {
            crypto_key = Cryption.IsExistKey(crypto_key) == false ? Cryption.DefaultKey : crypto_key;

            Cryption _cryptor = __Cryptors.Value.Find
                                (
                delegate(Cryption cryptor)
            {
                return(cryptor.SelectedKey == crypto_key);
            }
                                );

            if (_cryptor == null)
            {
                _cryptor = new OdinSdk.OdinLib.Security.Cryption(crypto_key);
                __Cryptors.Value.Add(_cryptor);
            }

            return(_cryptor);
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------------------------------------------------------------
        //
        //-----------------------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// write package
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="kind_of_packing"></param>
        /// <param name="object_value"></param>
        /// <param name="crypto_key"></param>
        /// <returns></returns>
        public XmlPackage WritePackage <T>(T object_value, MKindOfPacking kind_of_packing = MKindOfPacking.Encrypted, string crypto_key = null)
        {
            var _xml_value = ObjectToString <T>(object_value);

            if (kind_of_packing.HasFlag(MKindOfPacking.Encrypted) == true)
            {
                if (Cryption.IsExistKey(crypto_key) == false)
                {
                    crypto_key = Cryption.GetRandomKey();
                }
            }

            if (kind_of_packing != MKindOfPacking.All)
            {
                if (kind_of_packing.HasFlag(MKindOfPacking.Encrypted) == true)
                {
                    _xml_value = CryptHelper.SNG.PlainToChiperText(_xml_value, false, crypto_key);
                }

                if (kind_of_packing.HasFlag(MKindOfPacking.Compressed) == true)
                {
                    _xml_value = CompressText(_xml_value);
                }
            }
            else
            {
                _xml_value = CryptHelper.SNG.PlainToChiperText(_xml_value, true, crypto_key);
            }

            return(new XmlPackage()
            {
                Packings = kind_of_packing,
                Value = _xml_value,
                CryptoKey = crypto_key
            });
        }