Example #1
0
            public Stats(Basis _BasisStats, FlatBonus _FlatBoni, PercentageBonus _PercentageBoni, ArmorTypes _ArmorType, DamageTypes _DamageType)
            {
                basis           = _BasisStats;
                flatBonus       = _FlatBoni;
                percentageBonus = _PercentageBoni;

                ArmorType  = _ArmorType;
                DamageType = _DamageType;

                this.current_Health          = max_Health;
                this.current_Strength        = max_Strength;
                this.current_HealthRegen     = max_HealthRegen;
                this.current_Mana            = max_Mana;
                this.current_Magic           = max_Magic;
                this.current_Intelligence    = max_Intelligence;
                this.current_ManaRegen       = max_ManaRegen;
                this.current_Rage            = max_Rage;
                this.current_Attack          = max_Attack;
                this.current_Energy          = max_Energy;
                this.current_WalkSpeed       = max_WalkSpeed;
                this.current_RunSpeed        = max_RunSpeed;
                this.current_Dexterity       = max_Dexterity;
                this.current_Armor           = max_Armor;
                this.current_MagicResistence = max_MagicResistence;
            }
        public ItemWrapper(ACDItem item)
        {
            ActorSNO            = item.ActorSNO;
            GameBalanceId       = item.GameBalanceId;
            DynamicID           = item.DynamicId;
            ACDGuid             = item.ACDGuid;
            InventorySlot       = item.InventorySlot;
            ValidInventorySlots = item.ValidInventorySlots;
            RequiredLevel       = item.RequiredLevel;
            IsUnidentified      = item.IsUnidentified;
            IsTwoHand           = item.IsTwoHand;
            IsOneHand           = item.IsOneHand;
            Name              = item.Name;
            InternalName      = item.InternalName;
            this.ItemType     = item.ItemType;
            this.ItemBaseType = item.ItemBaseType;
            IsShield          = ShieldTypes.Contains(ItemType);
            IsOffHand         = OffHandTypes.Contains(ItemType);
            IsArmor           = ArmorTypes.Contains(ItemType);
            IsJewlery         = JewleryTypes.Contains(ItemType);
            IsWeapon          = WeaponTypes.Contains(ItemType);
            IsMisc            = MiscTypes.Contains(ItemType);

            HasSingleUseSlot = IsSingleSlotItem();

            Item  = item;
            Stats = item.Stats;
        }
Example #3
0
        public void SetAllStats(int[] primary, int[] secondary, int[] defense, int[] element, int[] armorType, int[] weaponType)
        {
            Primary.SetAll(primary);
            Secondary.SetAll(secondary);
            Defense.SetAll(defense);
            ElementDefense.SetAll(element);
            ArmorTypes.SetAll(armorType);
            WeaponTypes.SetAll(weaponType);

            Major.SetAll
            (
                new int[]
            {
                (
                    Secondary.Stats[SecondaryFlag.Vitality].Value *
                    Primary.Stats[PrimaryFlag.Con].Value *
                    UnitLevel.Value
                ),
                (
                    Primary.Stats[PrimaryFlag.Str].Value +
                    Primary.Stats[PrimaryFlag.Dex].Value +
                    Primary.Stats[PrimaryFlag.Con].Value +
                    PowerBonus()
                ),
                (
                    Primary.Stats[PrimaryFlag.Int].Value +
                    Primary.Stats[PrimaryFlag.Wis].Value +
                    Primary.Stats[PrimaryFlag.Cha].Value +
                    MagicBonus()
                )
            }
            );
        }
Example #4
0
    public static void CreateArmor(ArmorTypes armorType, Transform parent = null)
    {
        GameObject armorObject = new GameObject("Armor", typeof(Armor));

        armorObject.GetComponent <Armor>().SetArmorStats(armorType);
        armorObject.transform.parent = parent;
    }
Example #5
0
        /// <summary>
        /// Finds a local or remote key given its fingerprint
        /// </summary>
        /// <param name="fingerprint">fingerprint</param>
        /// <returns>a public key</returns>
        public TransportablePublicKey FindPublicKey(string fingerprint)
        {
            IEnumerator ieKeys = this.PublicKeys.GetEnumerator();

            while (ieKeys.MoveNext())
            {
                if (!(ieKeys.Current is TransportablePublicKey))
                {
                    continue;
                }
                TransportablePublicKey key = ((TransportablePublicKey)ieKeys.Current);
                if (key.PrimaryKey.Fingerprint.ToString() == fingerprint)
                {
                    return(key);
                }
            }

            ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();
            string remoteKey           = kf.MyLDAPSearch(SharpPrivacyLibrary.LdapKeyServer, SharpPrivacyLibrary.LdapPort, "pgpkey", "(pgpsignerid=" + fingerprint + ")");

            if (remoteKey != null)
            {
                ArmorTypes atType = new ArmorTypes();
                string     strKey = Armor.RemoveArmor(remoteKey, ref atType, ref remoteKey);
                if (strKey.Length > 0)
                {
                    TransportablePublicKey tpkKey = new TransportablePublicKey(strKey);
                    AddPublicKey(tpkKey);
                    return(tpkKey);
                }
            }

            return(null);
        }
Example #6
0
    void Awake()
    {
        //     Animator anim = GetComponent<Animator>();
        //     anim.SetInteger("Health", CurrentHealth);


        if (gameObject.tag == TagsManager.Player)
        {
            Player = true;
        }
        if (gameObject.tag == TagsManager.DestroyableObject)
        {
            DestroybleObject = true;
        }

        switch (ArmorType)
        {
        case ArmorTypes.None: Hardness = 20f; break;

        case ArmorTypes.Lite: Hardness = 26f; break;

        case ArmorTypes.Medium: Hardness = 33.8f; break;

        case ArmorTypes.Heavy: Hardness = 43.94f; break;

        case ArmorTypes.Ultra: Hardness = 57.12f; break;
        }

        if (DestroybleObject)
        {
            MyDestroyableObject = GetComponent <DestroyableObject>();
            ArmorType           = ArmorTypes.None;
            Hardness            = 10f;
        }
    }
Example #7
0
 public ArmorSet(ArmorTypes type, string name, List <string> lore) : base()
 {
     Lore      = lore;
     Name      = name;
     ArmorType = type;
     Amount    = 1;
 }
Example #8
0
        public ulong GetDecryptionKey(string strMessage)
        {
            ArmorTypes atType     = new ArmorTypes();
            string     strRest    = "";
            string     strRadix64 = Armor.RemoveArmor(strMessage, ref atType, ref strRest);

            if (strRadix64.Length == 0)
            {
                throw new Exception("This is not a valid OpenPGP message!");
            }

            EncryptedMessage emMessage = new EncryptedMessage();

            Packet[] pPackets = Packet.ParsePackets(strRadix64);

            emMessage.ParseMessage(pPackets);

            if (!emMessage.SymmetricallyEncrypted)
            {
                ulong lKeyID = emMessage.GetFittingKeyID(skrKeyRing);
                return(lKeyID);
            }
            else
            {
                return(0ul);
            }
        }
Example #9
0
        /// <summary>
        /// Loads a keyring file
        /// </summary>
        /// <param name="strPath">The keyring file location</param>
        public void Load(string strPath)
        {
            strLoadingPath = strPath;
            System.IO.StreamReader srInput = new StreamReader(strPath);
            string strKeys = srInput.ReadToEnd();

            srInput.Close();

            this.SecretKeys = new ArrayList();

            ArmorTypes atType = new ArmorTypes();
            string     strKey = Armor.RemoveArmor(strKeys, ref atType, ref strKeys);

            while (strKey.Length > 0)
            {
                TransportableSecretKey[] tskKeys = TransportableSecretKey.SplitKeys(strKey);
                foreach (TransportableSecretKey tskKey in tskKeys)
                {
                    this.SecretKeys.Add(tskKey);
                }

                strKey = Armor.RemoveArmor(strKeys, ref atType, ref strKeys);
            }
            bIsUpdated = false;
        }
Example #10
0
 public static Armor GetArmor(ArmorTypes armorType)
 {
     return(armorType switch
     {
         ArmorTypes.CopperArmor => new Armor(armorType, 10),
         ArmorTypes.IronArmor => new Armor(armorType, 15),
         _ => null
     });
Example #11
0
 public Armor(int armorMin, int durability, ArmorTypes type, int armorMax, BodyPart equipLocation)
 {
     this.Name          = type.ToString();
     this.Durability    = durability;
     this.EquipLocation = BodyPart.Chest;
     this.ArmorValue    = GetArmorValue(armorMin, armorMax);
     this.EquipLocation = equipLocation;
 }
Example #12
0
 public Armor(int armorMin, int durability, ArmorTypes type, int armorMax, BodyPart equipLocation)
 {
     this.Name = type.ToString();
     this.Durability = durability;
     this.EquipLocation = BodyPart.Chest;
     this.ArmorValue = GetArmorValue(armorMin, armorMax);
     this.EquipLocation = equipLocation;
 }
Example #13
0
        /// <todo>
        /// This could use some work. I dispute the notion that an Armor's material should not be a member variable,
        /// calling into question the need for this method.
        /// </todo>
        public static double CalculateAR(ArmorTypes type, ArmorMaterials material, ArmorQualities quality)
        {
            double result = 0;

            result += ArmorTypeData.s_modifiers[(int)type];
            result += ArmorMaterialData.s_modifiers[(int)material];
            result += result * ArmorQualityData.s_modifiers[(int)quality];

            return(result);
        }
Example #14
0
 public Armor(int id, string name, int defenseBonus, HardnessScale armorHardness, ArmorTypes armorType)
 {
     //base();
     ID   = id;
     Name = "EquipedArmor";
     //ItemType = ItemTypes.Armor;
     ArmorName     = Name;
     DefenseBonus  = defenseBonus;
     ArmorHardness = armorHardness;
     ArmorType     = armorType;
 }
Example #15
0
        public ItemWrapper(ACDItem item)
        {
            try
            {
                ActorSNO            = item.ActorSNO;
                GameBalanceId       = item.GameBalanceId;
                DynamicId           = item.DynamicId;
                ACDGuid             = item.ACDGuid;
                InventorySlot       = item.InventorySlot;
                ValidInventorySlots = item.ValidInventorySlots;
                RequiredLevel       = item.RequiredLevel;
            }
            catch (Exception ex)
            {
                Logger.LogError("Error wrapping non-attribute properties on item {0}: " + ex);
            }
            try
            {
                Name                  = item.Name;
                IsUnidentified        = item.IsUnidentified;
                IsTwoHand             = item.IsTwoHand;
                IsOneHand             = item.IsOneHand;
                InternalName          = item.InternalName;
                ItemType              = item.ItemType;
                ItemBaseType          = item.ItemBaseType;
                IsShield              = ShieldTypes.Contains(ItemType);
                IsOffHand             = OffHandTypes.Contains(ItemType);
                IsArmor               = ArmorTypes.Contains(ItemType);
                IsJewelry             = JewleryTypes.Contains(ItemType);
                IsWeapon              = WeaponTypes.Contains(ItemType);
                IsEquipment           = item.ItemBaseType == ItemBaseType.Armor || item.ItemBaseType == ItemBaseType.Jewelry || item.ItemBaseType == ItemBaseType.Weapon;
                IsMisc                = MiscTypes.Contains(ItemType);
                IsGem                 = item.ItemBaseType == ItemBaseType.Gem;
                IsTwoSquareItem       = (item.ItemBaseType == ItemBaseType.Armor || item.ItemBaseType == ItemBaseType.Weapon) && item.IsTwoSquareItem;
                IsPotion              = item.IsPotion;
                ItemQualityLevel      = item.ItemQualityLevel;
                GemQuality            = item.GemQuality;
                TieredLootRunKeyLevel = item.TieredLootRunKeyLevel;
                ItemStackQuantity     = item.ItemStackQuantity;
                IsSetItem             = item.IsSetItem();
                ItemSetName           = item.ItemSetName();

                HasSingleUseSlot = IsSingleSlotItem();

                Item          = item;
                Stats         = item.Stats;
                StatsData     = ItemStatsDataFactory.GetItemStatsDataFromStats(Stats);
                ReferenceItem = new Item(Item);
            }
            catch (Exception ex)
            {
                Logger.LogError("Error wrapping item {0}: " + ex);
            }
        }
Example #16
0
 public ArmorTemplate(string name = "No Armor", ArmorCategories category = ArmorCategories.None, ArmorTypes baseArmorType = ArmorTypes.NoArmor, int baseAC = 10, int maxDexBonus = 10, bool stealthDisadvantage = false, int strengthReq = 0, int cost = 0, int weight = 0)
 {
     this.name                = name;
     this.category            = category;
     this.baseArmorType       = baseArmorType;
     this.baseAC              = baseAC;
     this.maxDexBonus         = maxDexBonus;
     this.stealthDisadvantage = stealthDisadvantage;
     this.strengthRequirement = strengthReq;
     this.cost                = cost;
     this.weight              = weight;
 }
Example #17
0
        public Armor()
        {
            itemType = ItemType.Armor.ToString();

            name                = "None";
            armorCategory       = ArmorCategories.None;
            baseArmorType       = ArmorTypes.NoArmor;
            baseAC              = 10;
            maxDexBonus         = 10;
            stealthDisadvantage = false;
            strengthRequirement = 0;
        }
Example #18
0
        public void AddKey(string strKey)
        {
            bool bNotImported = false;
            bool bError = false;

            string strRest = "";
            ArmorTypes atType = new ArmorTypes();
            do {
                strKey = Armor.RemoveArmor(strKey, ref atType, ref strRest);
                if (atType == ArmorTypes.PrivateKeyBlock) {
                    try {
                        TransportableSecretKey[] tskKeys = TransportableSecretKey.SplitKeys(strKey);
                        for (int i=0; i<tskKeys.Length; i++) {
                            TransportableSecretKey tskKey = tskKeys[i];
                            TransportableSecretKey tskTestKey = skrKeyRing.Find(tskKey.PrimaryKey.PublicKey.KeyID);
                            if (tskTestKey != null) {
                                bNotImported = true;
                                continue;
                            }
                            skrKeyRing.AddSecretKey(tskKey);
                        }
                    } catch (Exception) {
                        bError = true;
                    }
                } else if (atType == ArmorTypes.PublicKeyBlock) {
                    try {
                        TransportablePublicKey[] tpkKeys = TransportablePublicKey.SplitKeys(strKey);
                        for (int i=0; i<tpkKeys.Length; i++) {
                            TransportablePublicKey tpkKey = tpkKeys[i];
                            TransportablePublicKey tpkTestKey = pkrKeyRing.Find(tpkKey.PrimaryKey.KeyID, true);
                            if (tpkTestKey != null) {
                                bNotImported = true;
                                continue;
                            }
                            pkrKeyRing.AddPublicKey(tpkKey);
                        }
                    } catch (Exception) {
                        bError = true;
                    }
                }
                strKey = strRest;
            } while (strKey.Length > 0);

            pkrKeyRing.Save();
            skrKeyRing.Save();

            if (bError)
                throw new Exception("Some keys could not be imported, because there were errors!");

            if (bNotImported)
                throw new Exception("Some keys could not be imported, because they were already in your keyring!");
        }
Example #19
0
        public string DecryptAndVerify(string strMessage, string strPassphrase)
        {
            ArmorTypes atType     = new ArmorTypes();
            string     strRest    = "";
            string     strRadix64 = Armor.RemoveArmor(strMessage, ref atType, ref strRest);

            if (strRadix64.Length == 0)
            {
                throw new Exception("This is not a valid OpenPGP message!");
            }

            return(this.DecryptAndVerifyData(Radix64.Decode(strRadix64), strPassphrase));
        }
Example #20
0
        public Armor(ArmorTemplate armor)
        {
            itemType = ItemType.Armor.ToString();

            name                = armor.name;
            armorCategory       = armor.category;
            baseArmorType       = armor.baseArmorType;
            baseAC              = armor.baseAC;
            maxDexBonus         = armor.maxDexBonus;
            stealthDisadvantage = armor.stealthDisadvantage;
            strengthRequirement = armor.strengthRequirement;
            cost                = armor.cost;
            weight              = armor.weight;
        }
Example #21
0
        internal Armor(Point location, int floorLevel)
        {
            itemClass = GameConstants.ItemClasses.Armor;
            Location  = location;
            // Decide if cursed
            isCursed = (Utility.Rand.Next(8) == 0);
            // Leather can be found anywhere, Chain increases in chance first, then Plate later
            float leatherProbability = 0.25f;
            float chainProbability   = MathHelper.Min(floorLevel < 5 ? 0 : 0.02f * floorLevel, 0.25f);
            float plateProbability   = MathHelper.Min(floorLevel < 15 ? 0 : 0.005f * floorLevel, 0.25f);

            int newType = 0;

            while (newType == 0)
            {
                int testType = Utility.Rand.Next(3) + 1;
                switch (testType)
                {
                case 1: if (Utility.Rand.NextDouble() < leatherProbability)
                    {
                        newType = testType;
                    }
                    break;

                case 2: if (Utility.Rand.NextDouble() < chainProbability)
                    {
                        newType = testType;
                    }
                    break;

                case 3: if (Utility.Rand.NextDouble() < plateProbability)
                    {
                        newType = testType;
                    }
                    break;
                }
            }

            switch (newType)
            {
            case 2: armorType = ArmorTypes.Chain; InventoryWeight = 40;  break;

            case 3: armorType = ArmorTypes.Plate; InventoryWeight = 50;  break;

            default: armorType = ArmorTypes.Leather; InventoryWeight = 15;  break;
            }
            armorBonus     = CalculateArmorBonus(armorType, isCursed);
            canRust        = (armorType == ArmorTypes.Chain || armorType == ArmorTypes.Plate);
            inventoryTitle = "some " + armorType + " armor";
        }
        public void LoadKey(string Key)
        {
            this.PublicKeys = new ArrayList();
            ArmorTypes atType = new ArmorTypes();
            //string strKey = Armor.RemoveArmor(Key, ref atType, ref Key);
            //while (strKey.Length > 0)
            //{
            TransportablePublicKey tpkKey = new TransportablePublicKey(Key);

            this.PublicKeys.Add(tpkKey);

            //strKey = Armor.RemoveArmor(Key, ref atType, ref Key);
            //}
            this.bIsUpdated = false;
        }
Example #23
0
        private static int CalculateArmorBonus(ArmorTypes type, bool curse)
        {
            // http://www.dandwiki.com/wiki/SRD:Armor
            switch (type)
            {
            case ArmorTypes.Leather:
                return(curse ? -1 : 2);

            case ArmorTypes.Chain:
                return(curse ? -2 : 5);    // Chainmail

            case ArmorTypes.Plate:
                return(curse ? -3 : 8);    // Full Plate

            default:
                return(0);
            }
        }
Example #24
0
        private void dgv_ArmorTypes_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (((DataGridView)sender).Rows[e.RowIndex].IsNewRow)
            {
                return;
            }
            if (!((DataGridView)sender).IsCurrentRowDirty)
            {
                return;
            }

            var armorRecord = (ArmorRecord)((DataGridView)sender).Rows[e.RowIndex].DataBoundItem;

            // Constraint: Must be explicit slot
            if (armorRecord.Slot == SlotTypes.Unknown)
            {
                MessageBox.Show(@"The Slot cannot be 'Unknown'.");
                e.Cancel = true;
            }

            // Constraint: Type and Slot must be unique combinations
            if (ArmorTypes.Where(c => c.Type.ToLower() == armorRecord.Type.ToLower()).Any(c => c.Slot != armorRecord.Slot))
            {
                MessageBox.Show($@"That Type '{armorRecord.Type}' already belongs to another Slot.");
                e.Cancel = true;
            }

            // Constraint: Type and Color must be unique combinations
            if (ArmorTypes.Count(c => c.Type.ToLower() == armorRecord.Type.ToLower() && c.Color == armorRecord.Color) > 1)
            {
                MessageBox.Show($@"There is already a Type '{armorRecord.Type}' and Color '{armorRecord.Color}'.");
                e.Cancel = true;
            }

            // Foreign Key: Resist Id must exist
            if (ResistConfigurations.All(c => c.Id != armorRecord.BaseResistConfigurationId))
            {
                MessageBox.Show($@"The Resist Id '{armorRecord.BaseResistConfigurationId}' does not exist.");
                e.Cancel = true;
            }
        }
Example #25
0
    public BaseArmors(int num, string name, string description, bool stackable, ItemTypes itemType, bool quest, bool inventoryBattle, int cost, string tag,
                      bool equipable, WhoCanEquips whoCanEquip,
                      int str, int inte, int agi, int sta, int vit, int spi,
                      int attPow, int magPow, int spe, int phyDmgRed, int magDmgRed, int hp, int mp,
                      int spellEffectInventoryID, bool spellEffectsEquipedID, double spellEffectEquipedPercent,
                      ArmorTypes armorType)
    {
        this.ItemID          = num;
        this.ItemName        = name;
        this.ItemDescription = description;
        this.Stackable       = stackable;
        this.ItemType        = itemType;
        this.Quest           = quest;
        this.InventoryBattle = InventoryBattle;
        this.Cost            = cost;
        this.ItemTag         = tag;

        this.Equipable   = equipable;
        this.WhoCanEquip = whoCanEquip;

        this.Strength  = str;
        this.Intellect = inte;
        this.Agility   = agi;
        this.Stamina   = sta;
        this.Vitality  = vit;
        this.Spirit    = spi;

        this.AttackPower = attPow;
        this.MagicPower  = magPow;
        this.Speed       = spe;
        this.PhyDmgNeg   = phyDmgRed;
        this.MagDmgNeg   = magDmgRed;
        this.HitPoints   = hp;
        this.ManaPoints  = mp;

        this.SpellEffectsInventoryID   = spellEffectInventoryID;
        this.SpellEffectsEquipedID     = spellEffectsEquipedID;
        this.SpellEffectEquipedPercent = spellEffectEquipedPercent / 100.0f;

        this.ArmorType = armorType;
    }
Example #26
0
        /// <summary>
        /// Finds a Key given a keyid. Performs a remote LDAP search if specified.
        /// </summary>
        /// <param name="lKeyID">Key to find</param>
        /// <param name="remote">LDAP search</param>
        /// <returns>a key</returns>
        public TransportablePublicKey Find(ulong lKeyID, bool remote)
        {
            IEnumerator ieKeys = alPublicKeys.GetEnumerator();

            while (ieKeys.MoveNext())
            {
                TransportablePublicKey tpkKey = (TransportablePublicKey)ieKeys.Current;
                if (tpkKey.PrimaryKey.KeyID == lKeyID)
                {
                    return(tpkKey);
                }
                IEnumerator ieSubkeys = tpkKey.SubKeys.GetEnumerator();
                while (ieSubkeys.MoveNext())
                {
                    CertifiedPublicSubkey cpsSubkey = (CertifiedPublicSubkey)ieSubkeys.Current;
                    if (cpsSubkey.Subkey.KeyID == lKeyID)
                    {
                        return(tpkKey);
                    }
                }
            }

            if (remote)
            {
                ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();

                string key = kf.MyLDAPSearch(SharpPrivacyLibrary.LdapKeyServer, SharpPrivacyLibrary.LdapPort, "pgpkey", "(pgpsignerid=" + lKeyID.ToString("X") + ")");
                if (key != null)
                {
                    ArmorTypes atType = new ArmorTypes();
                    string     strKey = Armor.RemoveArmor(key, ref atType, ref key);
                    if (strKey.Length > 0)
                    {
                        TransportablePublicKey tpkKey = new TransportablePublicKey(strKey);
                        AddPublicKey(tpkKey);
                        return(tpkKey);
                    }
                }
            }
            return(null);
        }
        public void Load(string strPath)
        {
            this.strLoadingPath = strPath;
            System.IO.StreamReader srInput = new StreamReader(strPath);
            string strKeys = srInput.ReadToEnd();

            srInput.Close();

            this.PublicKeys = new ArrayList();

            ArmorTypes atType = new ArmorTypes();
            string     strKey = Armor.RemoveArmor(strKeys, ref atType, ref strKeys);

            while (strKey.Length > 0)
            {
                TransportablePublicKey tpkKey = new TransportablePublicKey(strKey);
                this.PublicKeys.Add(tpkKey);

                strKey = Armor.RemoveArmor(strKeys, ref atType, ref strKeys);
            }
            this.bIsUpdated = false;
        }
Example #28
0
 public BaseArmorItem(
     string itemName,
     string itemDescription,
     int itemId,
     EquipmentTypes equipmentType,
     ItemTypes itemType,
     ArmorTypes armorType,
     int stackSize,
     Sprite spriteNeutral,
     Sprite spriteHighlighted,
     int stamina,
     int strenght,
     int agility,
     int endurance,
     int intelect,
     int resistance,
     int magicResistance
     )
     : base(
         itemName,
         itemDescription,
         itemId,
         equipmentType,
         itemType,
         stackSize,
         spriteNeutral,
         spriteHighlighted,
         stamina,
         strenght,
         agility,
         endurance,
         intelect,
         resistance,
         magicResistance
         )
 {
     this.armorType = armorType;
 }
Example #29
0
 void Setup(ShipDesign template)
 {
     DesignClass = template;
     foreach (ShipComponents c in template.Components)
     {
         ShipComponents copy = c.CloneProperties();
         Components.Add(copy);
     }
     UpdateComponentStatusStrings();
     SetupArmor(template.ArmorLength, template.ArmorLayers, (float)template.ArmorType / 10);
     if (template.ArmorLayers > 0)
     {
         Armored = true;
     }
     mCrew = template.CrewMin;
     ChangeStats();
     ArmorType = template.ArmorType;
     ChangeStats();
     UpdateMaint();
     AddHistory("Launched", string.Format("{0}: {1} is launched.", StrategicClock.GetDate(), ShipName));
     CommissionDate = StrategicClock.GetDate();
     Hull           = template.Hull.Clone();
 }
Example #30
0
        /// <summary>
        /// Finds a Key given a keyid. Performs a remote LDAP search if specified.
        /// </summary>
        /// <param name="lKeyID">Key to find</param>
        /// <param name="remote">LDAP search</param>
        /// <returns>a key</returns>
        public TransportablePublicKey Find(ulong lKeyID, bool remote)
        {
            IEnumerator ieKeys = alPublicKeys.GetEnumerator();
            while (ieKeys.MoveNext()) {
                TransportablePublicKey tpkKey = (TransportablePublicKey)ieKeys.Current;
                if (tpkKey.PrimaryKey.KeyID == lKeyID) {
                    return tpkKey;
                }
                IEnumerator ieSubkeys = tpkKey.SubKeys.GetEnumerator();
                while (ieSubkeys.MoveNext()) {
                    CertifiedPublicSubkey cpsSubkey = (CertifiedPublicSubkey)ieSubkeys.Current;
                    if (cpsSubkey.Subkey.KeyID == lKeyID)
                        return tpkKey;
                }
            }

            if (remote) {
                ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();

                string key = kf.MyLDAPSearch(SharpPrivacyLibrary.LdapKeyServer, SharpPrivacyLibrary.LdapPort,"pgpkey","(pgpsignerid="+lKeyID.ToString("X")+")");
                if (key != null) {
                    ArmorTypes atType = new ArmorTypes();
                    string strKey = Armor.RemoveArmor(key, ref atType, ref key);
                    if (strKey.Length > 0) {
                        TransportablePublicKey tpkKey = new TransportablePublicKey(strKey);
                        AddPublicKey(tpkKey);
                        return tpkKey;
                    }
                }
            }
            return null;
        }
Example #31
0
 private int findAC(int ac, ArmorTypes armor, int dexMod)
 {
     switch (armor)
     {
         case ArmorTypes.LightArmor:
             return (ac + dexMod);
         case ArmorTypes.MediumArmor:
             if (dexMod > 2)
                 return (ac + 2);
             else
                 return (ac + dexMod);
         default:
             return ac;
     }
 }
Example #32
0
        /// <summary>
        /// Finds a local or remote key given its fingerprint
        /// </summary>
        /// <param name="fingerprint">fingerprint</param>
        /// <returns>a public key</returns>
        public TransportablePublicKey FindPublicKey(string fingerprint)
        {
            IEnumerator ieKeys = this.PublicKeys.GetEnumerator();
            while (ieKeys.MoveNext()) {
                if (!(ieKeys.Current is TransportablePublicKey)) {
                    continue;
                }
                TransportablePublicKey key = ((TransportablePublicKey)ieKeys.Current);
                if(key.PrimaryKey.Fingerprint.ToString() == fingerprint) {
                    return key;
                }
            }

            ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();
            string remoteKey = kf.MyLDAPSearch(SharpPrivacyLibrary.LdapKeyServer,SharpPrivacyLibrary.LdapPort,"pgpkey","(pgpsignerid="+fingerprint+")");
            if (remoteKey != null) {
                ArmorTypes atType = new ArmorTypes();
                string strKey = Armor.RemoveArmor(remoteKey, ref atType, ref remoteKey);
                if (strKey.Length > 0) {
                    TransportablePublicKey tpkKey = new TransportablePublicKey(strKey);
                    AddPublicKey(tpkKey);
                    return tpkKey;
                }
            }

            return null;
        }
        /// <summary>
        /// Verifies the signature given a signed file and a signature file
        /// </summary>
        /// <param name="strFile">signature file bytes</param>
        /// <param name="fileToVerify">signed file</param>
        /// <returns></returns>
        private string FileSignatureVerify(byte[] bData, string fileToVerify)
        {
            SharpPrivacy.SharpPrivacyLib.OpenPGP.Messages.Message mContent = null;
            byte[] decodedbData = null;
            string strMessage = System.Text.Encoding.UTF8.GetString(bData);
            ArmorTypes atType = new ArmorTypes();
            string strRest = "";
            string strRadix64 = Armor.RemoveArmor(strMessage, ref atType, ref strRest);
            if (strRadix64.Length > 0)
                decodedbData = Radix64.Decode(strRadix64);

            if (atType == ArmorTypes.OpenPGPSignature) {
                SignedMessage smMessage = new SignedMessage();
                Packet[] pPackets;

                pPackets = Packet.ParsePackets(decodedbData);

                if (!(pPackets[0] is SignaturePacket)) {
                    throw new Exception("Not a valid cleartext signature!");
                }

                smMessage.Signature = (SignaturePacket)pPackets[0];

                mContent = smMessage;
            } else {
                // let us see what kind of message this is
                Packet[] pPackets;
                try {
                    pPackets = Packet.ParsePackets(bData);
                    mContent = new SignedMessage();
                    ((SignedMessage)mContent).Signature = (SignaturePacket)pPackets[0];
                    //((SignedMessage)mContent).OnePassSigned = false;
                } catch (Exception ee) {
                    throw new Exception("There was an error decrypting your message: " + ee.Message);
                }
            }

            byte[] bFileContent = new byte[0];
            try {
                System.IO.FileStream fsFile = new FileStream(fileToVerify, FileMode.Open);
                BinaryReader brReader = new BinaryReader(fsFile);
                bFileContent = brReader.ReadBytes((int)fsFile.Length);
                brReader.Close();
                fsFile.Close();
            } catch (Exception e) {
                throw new Exception("An error occured while opening the file " + e.Message);
            }

            LiteralMessage lmMessage = new LiteralMessage(DataFormatTypes.Binary);
            lmMessage.Binary = bFileContent;
            lmMessage.TimeCreated = ((SignedMessage)mContent).Signature.TimeCreated;
            lmMessage.Filename = fileToVerify;
            ((SignedMessage)mContent).MessageSigned = lmMessage;

            LiteralMessage lmContent = new LiteralMessage();
            string strDisplay = "";
            if (mContent is SignedMessage) {
                SignedMessage smContent = (SignedMessage)mContent;
                lmContent = smContent.MessageSigned;
                strDisplay += "*** OpenPGP Signed Message ***\r\n";
                strDisplay += "*** Signature Status: " + smContent.Verify(pkrPublicKeyRing) + " ***\r\n";
                strDisplay += "*** Signing Key: " + smContent.Signature.KeyID.ToString("x") + " ***\r\n";
                try {
                    try {
                        strDisplay += "*** Signing Key Expiration: " + pkrPublicKeyRing.Find(smContent.Signature.KeyID,true).KeyExpirationTime + " ***\r\n";
                    } catch(Exception e) {
                        if(e.Message.Equals("never")) {
                            strDisplay += "*** Signing Key Expiration: "+e.Message+" ***\r\n";
                        } else {
                            throw new Exception("Signing_Key_Not_Available");
                        }

                    }
                    try {
                        strDisplay += "*** Signing Key Revoked: "+ this.pkrPublicKeyRing.isRevoked(smContent.Signature.KeyID) +" ***\r\n";
                    } catch(Exception e) {
                        string msg = e.Message;
                        strDisplay += "*** Signing Key Revoked: Revocation_Key_Not_Available ***\r\n";
                    }
                }
                catch (Exception e) {
                    string warn = e.Message;
                    strDisplay += "*** Signing Key Expiration: " + SignatureStatusTypes.Signing_Key_Not_Available + " ***\r\n";
                }
                strDisplay += "*** Signing Date: " + smContent.Signature.TimeCreated.ToString() + "***\r\n\r\n";
            } else if (mContent is LiteralMessage) {
                lmContent = (LiteralMessage)mContent;
                strDisplay += "*** OpenPGP Encrypted Message ***\r\n\r\n";
            } else {
                throw new Exception("An error occured: Could not find an encrypted or signed message!");
            }

            if (lmContent.DataFormat == DataFormatTypes.Text) {
                strDisplay += lmContent.Text;
                strDisplay += "\r\n\r\n*** End OpenPGP Message ***\r\n";
            }
            return strDisplay;
        }
        /// <summary>
        /// Method handling decrypting and verifying
        /// </summary>
        /// <param name="bData">data to be decrypted</param>
        /// <param name="strPassphrase">passphrase</param>
        /// <param name="fileOut">the decrypted file location if one produced</param>
        /// <returns>verifying process result</returns>
        private string DecryptAndVerify(byte[] bData, string strPassphrase, string fileOut)
        {
            string strMessage = System.Text.Encoding.UTF8.GetString(bData);
            ArmorTypes atType = new ArmorTypes();
            string strRest = "";
            string strRadix64 = Armor.RemoveArmor(strMessage, ref atType, ref strRest);
            if (strRadix64.Length > 0)
                bData = Radix64.Decode(strRadix64);

            SharpPrivacy.SharpPrivacyLib.OpenPGP.Messages.Message mContent = null;

            if (atType == ArmorTypes.OpenPGPSignedMessage) {
                string strSignature = "";
                string strSignedMessage = Armor.RemoveClearSignatureArmor(strMessage, ref atType, ref strSignature);

                strSignedMessage = Radix64.DashUnescape(strSignedMessage);
                strSignedMessage = Radix64.TrimMessage(strSignedMessage);
                SignedMessage smMessage = new SignedMessage();
                Packet[] pPackets;

                pPackets = Packet.ParsePackets(strSignature);

                if (!(pPackets[0] is SignaturePacket)) {
                    throw new Exception("Not a valid cleartext signature!");
                }
                smMessage.Signature = (SignaturePacket)pPackets[0];

                LiteralMessage lmMessage = new LiteralMessage(DataFormatTypes.Text);
                lmMessage.Text = strSignedMessage;
                smMessage.MessageSigned = lmMessage;

                mContent = smMessage;
            } else {

                // let us see what kind of message this is
                EncryptedMessage emMessage = new EncryptedMessage();
                Packet[] pPackets;
                try {
                    pPackets = Packet.ParsePackets(bData);
                    try {
                        emMessage.ParseMessage(pPackets);

                        if (emMessage.SymmetricallyEncrypted) {
                            // Query passphrase for symmetrically encrypted message

                            mContent = emMessage.Decrypt(strPassphrase);

                        } else {
                            ulong lKeyID = emMessage.GetFittingKeyID(skrSecretKeyRing);
                            mContent = emMessage.Decrypt(skrSecretKeyRing, strPassphrase);
                        }
                    } catch (Exception) {
                        mContent = new CompressedMessage();
                        mContent.ParseMessage(pPackets);
                    }

                    while ((!(mContent is LiteralMessage)) && (!(mContent is SignedMessage))) {
                        if (mContent is CompressedMessage) {
                            mContent = ((CompressedMessage)mContent).Uncompress();
                        } else {
                            throw new Exception("This is not a valid OpenPGP message!");
                        }
                    }
                } catch (Exception ee) {
                    throw new Exception("There was an error decrypting your message: " + ee.Message);
                }
            }

            LiteralMessage lmContent = new LiteralMessage();
            string strDisplay = "";
            if (mContent is SignedMessage) {
                SignedMessage smContent = (SignedMessage)mContent;
                lmContent = smContent.MessageSigned;
                strDisplay += "*** OpenPGP Signed Message ***\r\n";
                strDisplay += "*** Signature Status: " + smContent.Verify(pkrPublicKeyRing) + " ***\r\n";
                strDisplay += "*** Signing Key Dec: " + smContent.Signature.KeyID.ToString() + " ***\r\n";
                strDisplay += "*** Signing Key Hex: " + smContent.Signature.KeyID.ToString("x") + " ***\r\n";
                try {
                    try {
                        strDisplay += "*** Signing Key Expiration: " + pkrPublicKeyRing.Find(smContent.Signature.KeyID,true).KeyExpirationTime + " ***\r\n";
                    } catch(Exception e) {
                        if(e.Message.Equals("never"))
                            strDisplay += "*** Signing Key Expiration: "+e.Message+" ***\r\n";
                        else
                            throw new Exception("Signing_Key_Not_Available");

                    }
                    try {
                        strDisplay += "*** Signing Key Revoked: "+ this.pkrPublicKeyRing.isRevoked(smContent.Signature.KeyID) +" ***\r\n";
                    } catch(Exception e) {
                        string msg = e.Message;
                        strDisplay += "*** Signing Key Revoked: Revocation_Key_Not_Available ***\r\n";
                    }
                } catch (Exception e) {
                    string warn = e.Message;
                    strDisplay += "*** Signing Key Expiration: " + SignatureStatusTypes.Signing_Key_Not_Available + " ***\r\n";
                }
                strDisplay += "*** Signing Date: " + smContent.Signature.TimeCreated.ToString() + "***\r\n\r\n";
            } else if (mContent is LiteralMessage) {
                lmContent = (LiteralMessage)mContent;
                strDisplay += "*** OpenPGP Encrypted Message ***\r\n\r\n";
            } else {
                throw new Exception("An error occured: Could not find an encrypted or signed message!");
            }

            if (lmContent.DataFormat == DataFormatTypes.Text) {
                strDisplay += lmContent.Text;
                strDisplay += "\r\n\r\n*** End OpenPGP Message ***\r\n";
                if(fileOut != null && fileOut != "") {
                    System.IO.FileStream fsOut = new FileStream(fileOut, FileMode.Create);
                    System.IO.BinaryWriter bwOut = new BinaryWriter(fsOut);
                    bwOut.Write(lmContent.Binary);
                    bwOut.Close();
                    fsOut.Close();
                }
            } else {
                System.IO.FileStream fsOut = new FileStream(fileOut, FileMode.Create);
                System.IO.BinaryWriter bwOut = new BinaryWriter(fsOut);
                bwOut.Write(lmContent.Binary);
                bwOut.Close();
                fsOut.Close();
            }
            return strDisplay;
        }
Example #35
0
        public static string RemoveClearSignatureArmor(string strMessage, ref ArmorTypes atType, ref string strSignature)
        {
            string[] strLines  = strMessage.Split('\n');
            string   strReturn = "";

            /* Codes for Positions:
             *  0: Not in an OpenPGP Message
             *  1: Armor Headers
             *  2: OpenPGP Message
             *  3: PGP Signature
             */
            int iPosition = 0;

            for (int i = 0; i < strLines.Length; i++)
            {
                if ((strLines[i].Length > 10) && (strLines[i].Substring(0, 2).Trim() == "--") && (iPosition == 2))
                {
                    strLines[i] = strLines[i].Trim();
                    iPosition   = 0;
                    switch (strLines[i])
                    {
                    case "-----BEGIN PGP SIGNATURE-----":
                        string[] strRestLines = new string[strLines.Length - i];
                        Array.Copy(strLines, i, strRestLines, 0, strLines.Length - (i + 1));
                        string strRest = String.Join("\n", strRestLines);
                        strSignature = Armor.RemoveArmor(strRest, ref atType, ref strRest);
                        return(strReturn.Substring(0, strReturn.Length - 2));

                    default:
                        iPosition = 2;
                        break;
                    }
                }

                if (iPosition == 2)
                {
                    strReturn += strLines[i].TrimEnd(null) + "\r\n";
                }

                if ((iPosition == 1) && (strLines[i].Trim().Length == 0))
                {
                    iPosition = 2;
                }

                if ((strLines[i].Length > 10) && (strLines[i].Trim().Substring(0, 2) == "--") && (iPosition == 0))
                {
                    strLines[i] = strLines[i].Trim();
                    iPosition   = 1;
                    switch (strLines[i])
                    {
                    case "-----BEGIN PGP SIGNED MESSAGE-----":
                        atType = ArmorTypes.OpenPGPSignature;
                        break;

                    default:
                        iPosition = 0;
                        break;
                    }
                }
            }

            return("");
        }
Example #36
0
 protected Armor(string id, decimal price, double weight, int protection, ArmorTypes type)
     : base(id, price, weight)
 {
     this.Protection = protection;
     this.ArmourType = type;
 }
Example #37
0
        /// <summary>
        /// Loads a keyring file
        /// </summary>
        /// <param name="strPath">The keyring file location</param>
        public void Load(string strPath)
        {
            strLoadingPath = strPath;
            System.IO.StreamReader srInput = new StreamReader(strPath);
            string strKeys = srInput.ReadToEnd();
            srInput.Close();

            this.SecretKeys = new ArrayList();

            ArmorTypes atType = new ArmorTypes();
            string strKey = Armor.RemoveArmor(strKeys, ref atType, ref strKeys);
            while (strKey.Length > 0) {
                TransportableSecretKey[] tskKeys = TransportableSecretKey.SplitKeys(strKey);
                foreach (TransportableSecretKey tskKey in tskKeys) {
                    this.SecretKeys.Add(tskKey);
                }

                strKey = Armor.RemoveArmor(strKeys, ref atType, ref strKeys);
            }
            bIsUpdated = false;
        }
        private static void DecryptAndVerify(SecretKeyRing skrSecretKeyRing, PublicKeyRing pkrPublicKeyRing, byte[] bData)
        {
            string strMessage = System.Text.Encoding.UTF8.GetString(bData);
            ArmorTypes atType = new ArmorTypes();
            string strRest = "";
            string strRadix64 = Armor.RemoveArmor(strMessage, ref atType, ref strRest);
            if (strRadix64.Length > 0)
                bData = Radix64.Decode(strRadix64);

            SharpPrivacy.OpenPGP.Messages.Message mContent = null;

            if (atType == ArmorTypes.OpenPGPSignature) {
                string strSignature = "";
                string strSignedMessage = Armor.RemoveClearSignatureArmor(strMessage, ref atType, ref strSignature);

                strSignedMessage = Radix64.DashUnescape(strSignedMessage);
                strSignedMessage = Radix64.TrimMessage(strSignedMessage);
                SignedMessage smMessage = new SignedMessage();
                Packet[] pPackets = Packet.ParsePackets(strSignature);
                if (!(pPackets[0] is SignaturePacket)) {
                    MessageBox.Show("Not a valid cleartext signature!");
                    return;
                }
                smMessage.Signature = (SignaturePacket)pPackets[0];

                LiteralMessage lmMessage = new LiteralMessage(DataFormatTypes.Text);
                lmMessage.Text = strSignedMessage;
                smMessage.MessageSigned = lmMessage;

                mContent = smMessage;
            } else {

                // let us see what kind of message this is
                EncryptedMessage emMessage = new EncryptedMessage();
                try {
                    Packet[] pPackets = Packet.ParsePackets(bData);
                    emMessage.ParseMessage(pPackets);

                    if (emMessage.SymmetricallyEncrypted) {
                        // Query passphrase for symmetrically encrypted message
                        QueryPassphrase qpPassphrase = new QueryPassphrase();
                        qpPassphrase.ShowMyDialog();
                        string strPassphrase = qpPassphrase.Passphrase;

                        mContent = emMessage.Decrypt(strPassphrase);

                    } else {
                        ulong lKeyID = emMessage.GetFittingKeyID(skrSecretKeyRing);
                        QueryPassphrase qpPassphrase = new QueryPassphrase();
                        qpPassphrase.ShowMyDialog(skrSecretKeyRing.Find(lKeyID));
                        string strPassphrase = qpPassphrase.Passphrase;

                        mContent = emMessage.Decrypt(skrSecretKeyRing, strPassphrase);
                    }

                    while ((!(mContent is LiteralMessage)) && (!(mContent is SignedMessage))) {
                        if (mContent is CompressedMessage) {
                            mContent = ((CompressedMessage)mContent).Uncompress();
                        } else {
                            MessageBox.Show("This is not a valid OpenPGP message!");
                            return;
                        }
                    }
                } catch (Exception ee) {
                    MessageBox.Show("There was an error decrypting your message: " + ee.Message);
                    return;
                }
            }

            LiteralMessage lmContent = new LiteralMessage();
            string strDisplay = "";
            if (mContent is SignedMessage) {
                SignedMessage smContent = (SignedMessage)mContent;
                lmContent = smContent.MessageSigned;
                strDisplay += "*** OpenPGP Signed Message ***\r\n";
                strDisplay += "*** Signature Status: " + smContent.Verify(pkrPublicKeyRing) + " ***\r\n";
                strDisplay += "*** Signing Key: " + smContent.Signature.KeyID.ToString("x") + " ***\r\n";
                strDisplay += "*** Signing Date: " + smContent.Signature.TimeCreated.ToString() + "***\r\n\r\n";
            } else if (mContent is LiteralMessage) {
                lmContent = (LiteralMessage)mContent;
                strDisplay += "*** OpenPGP Encrypted Message ***\r\n\r\n";
            } else {
                MessageBox.Show("An error occured: Could not find an encrypted or signed message!", "Error...");
                return;
            }

            if (lmContent.DataFormat == DataFormatTypes.Text) {
                strDisplay += lmContent.Text;
                strDisplay += "\r\n\r\n*** End OpenPGP Message ***\r\n";
                PlaintextViewer pvViewer = new PlaintextViewer();
                pvViewer.MessageText = strDisplay;
                pvViewer.Show();
            } else {
                if (MessageBox.Show(strDisplay, "Signature Status...", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1) == DialogResult.OK) {
                    System.Windows.Forms.SaveFileDialog sfdSave = new SaveFileDialog();
                    sfdSave.OverwritePrompt = true;
                    sfdSave.Filter = "All Files (*.*)|*.*";
                    sfdSave.FileName = lmContent.Filename;
                    sfdSave.ShowDialog();
                    if (sfdSave.FileName.Length > 0) {
                        System.IO.FileStream fsOut = new FileStream(sfdSave.FileName, FileMode.CreateNew);
                        System.IO.BinaryWriter bwOut = new BinaryWriter(fsOut);
                        bwOut.Write(lmContent.Binary);
                        bwOut.Close();
                        fsOut.Close();
                    }
                }
            }
        }
Example #39
0
        public static string RemoveArmor(string strMessage, ref ArmorTypes atType, ref string strRest)
        {
            string[] strLines = strMessage.Split('\n');
            string strReturn = "";
            bool foundSignedMessage = false;

            /* Codes for Positions:
             *  0: Not in an OpenPGP Message
             *  1: Armor Headers
             *  2: OpenPGP Message
             */
            int iPosition = 0;

            for (int i=0; i<strLines.Length; i++) {
                if ((strLines[i].Length > 10) && (strLines[i].Substring(0, 2).Trim() == "--") && (iPosition == 2)) {
                    strLines[i] = strLines[i].Trim();
                    iPosition = 0;
                    switch (strLines[i]) {
                        case "-----END PGP MESSAGE-----":
                        case "-----END PGP PUBLIC KEY BLOCK-----":
                        case "-----END PGP PRIVATE KEY BLOCK-----":
                        case "-----END PGP SIGNATURE-----":
                            string[] strRestLines = new string[strLines.Length - (i+1)];
                            Array.Copy(strLines, i+1, strRestLines, 0, strLines.Length - (i+1));
                            strRest = String.Join("\n", strRestLines);
                            return strReturn;

                        default:
                            iPosition = 2;
                            break;
                    }
                }

                if (iPosition == 2) {
                    strReturn += strLines[i];
                }

                if ((iPosition == 1) && (strLines[i].Trim().Length == 0)) {
                    iPosition = 2;
                }

                if ((strLines[i].Length > 10) && (strLines[i].Trim().Substring(0, 2) == "--") && (iPosition == 0)) {
                    strLines[i] = strLines[i].Trim();
                    iPosition = 1;
                    switch (strLines[i]) {
                        case "-----BEGIN PGP MESSAGE-----":
                            atType = ArmorTypes.OpenPGPMessage;
                            break;

                        case "-----BEGIN PGP PUBLIC KEY BLOCK-----":
                            atType = ArmorTypes.PublicKeyBlock;
                            break;

                        case "-----BEGIN PGP PRIVATE KEY BLOCK-----":
                            atType = ArmorTypes.PrivateKeyBlock;
                            break;

                        case "-----BEGIN PGP SIGNATURE-----":
                            if (!foundSignedMessage)
                                atType = ArmorTypes.OpenPGPSignature;
                            break;

                        case "-----BEGIN PGP SIGNED MESSAGE-----":
                            atType = ArmorTypes.OpenPGPSignedMessage;
                            iPosition = 0;
                            foundSignedMessage = true;
                            break;

                        default:
                            iPosition = 0;
                            break;
                    }
                }
            }

            return "";
        }
Example #40
0
        public static string RemoveClearSignatureArmor(string strMessage, ref ArmorTypes atType, ref string strSignature)
        {
            string[] strLines = strMessage.Split('\n');
            string strReturn = "";

            /* Codes for Positions:
             *  0: Not in an OpenPGP Message
             *  1: Armor Headers
             *  2: OpenPGP Message
             *  3: PGP Signature
             */
            int iPosition = 0;

            for (int i=0; i<strLines.Length; i++) {
                if ((strLines[i].Length > 10) && (strLines[i].Substring(0, 2).Trim() == "--") && (iPosition == 2)) {
                    strLines[i] = strLines[i].Trim();
                    iPosition = 0;
                    switch (strLines[i]) {
                        case "-----BEGIN PGP SIGNATURE-----":
                            string[] strRestLines = new string[strLines.Length - i];
                            Array.Copy(strLines, i, strRestLines, 0, strLines.Length - (i+1));
                            string strRest = String.Join("\n", strRestLines);
                            strSignature = Armor.RemoveArmor(strRest, ref atType, ref strRest);
                            return strReturn.Substring(0, strReturn.Length - 2);

                        default:
                            iPosition = 2;
                            break;
                    }
                }

                if (iPosition == 2) {
                    strReturn += strLines[i].TrimEnd(null) + "\r\n";
                }

                if ((iPosition == 1) && (strLines[i].Trim().Length == 0)) {
                    iPosition = 2;
                }

                if ((strLines[i].Length > 10) && (strLines[i].Trim().Substring(0, 2) == "--") && (iPosition == 0)) {
                    strLines[i] = strLines[i].Trim();
                    iPosition = 1;
                    switch (strLines[i]) {
                        case "-----BEGIN PGP SIGNED MESSAGE-----":
                            atType = ArmorTypes.OpenPGPSignature;
                            break;

                        default:
                            iPosition = 0;
                            break;
                    }
                }
            }

            return "";
        }
Example #41
0
 public Armor(string name, ArmorTypes atype, int aclass, decimal value)
 {
     Name = name;
     aType = atype;
     AC = aclass;
     Value = value;
 }
Example #42
0
 // Use this for initialization
 void Start()
 {
     InputDesiredDisplacement.onValueChanged.AddListener(SetDisplacement);
     button.onClick.AddListener(ProxySetDisplacement);
     ArmorTypes ArmorType = ArmorTypes.STEEL;
 }
Example #43
0
        public string DecryptAndVerify(string strMessage, string strPassphrase)
        {
            ArmorTypes atType = new ArmorTypes();
            string strRest = "";
            string strRadix64 = Armor.RemoveArmor(strMessage, ref atType, ref strRest);
            if (strRadix64.Length == 0)
                throw new Exception("This is not a valid OpenPGP message!");

            return this.DecryptAndVerifyData(Radix64.Decode(strRadix64), strPassphrase);
        }
Example #44
0
        public static string RemoveArmor(string strMessage, ref ArmorTypes atType, ref string strRest)
        {
            string[] strLines           = strMessage.Split('\n');
            string   strReturn          = "";
            bool     foundSignedMessage = false;

            /* Codes for Positions:
             *  0: Not in an OpenPGP Message
             *  1: Armor Headers
             *  2: OpenPGP Message
             */
            int iPosition = 0;

            for (int i = 0; i < strLines.Length; i++)
            {
                if ((strLines[i].Length > 10) && (strLines[i].Substring(0, 2).Trim() == "--") && (iPosition == 2))
                {
                    strLines[i] = strLines[i].Trim();
                    iPosition   = 0;
                    switch (strLines[i])
                    {
                    case "-----END PGP MESSAGE-----":
                    case "-----END PGP PUBLIC KEY BLOCK-----":
                    case "-----END PGP PRIVATE KEY BLOCK-----":
                    case "-----END PGP SIGNATURE-----":
                        string[] strRestLines = new string[strLines.Length - (i + 1)];
                        Array.Copy(strLines, i + 1, strRestLines, 0, strLines.Length - (i + 1));
                        strRest = String.Join("\n", strRestLines);
                        return(strReturn);

                    default:
                        iPosition = 2;
                        break;
                    }
                }

                if (iPosition == 2)
                {
                    strReturn += strLines[i];
                }

                if ((iPosition == 1) && (strLines[i].Trim().Length == 0))
                {
                    iPosition = 2;
                }

                if ((strLines[i].Length > 10) && (strLines[i].Trim().Substring(0, 2) == "--") && (iPosition == 0))
                {
                    strLines[i] = strLines[i].Trim();
                    iPosition   = 1;
                    switch (strLines[i])
                    {
                    case "-----BEGIN PGP MESSAGE-----":
                        atType = ArmorTypes.OpenPGPMessage;
                        break;

                    case "-----BEGIN PGP PUBLIC KEY BLOCK-----":
                        atType = ArmorTypes.PublicKeyBlock;
                        break;

                    case "-----BEGIN PGP PRIVATE KEY BLOCK-----":
                        atType = ArmorTypes.PrivateKeyBlock;
                        break;

                    case "-----BEGIN PGP SIGNATURE-----":
                        if (!foundSignedMessage)
                        {
                            atType = ArmorTypes.OpenPGPSignature;
                        }
                        break;

                    case "-----BEGIN PGP SIGNED MESSAGE-----":
                        atType             = ArmorTypes.OpenPGPSignedMessage;
                        iPosition          = 0;
                        foundSignedMessage = true;
                        break;

                    default:
                        iPosition = 0;
                        break;
                    }
                }
            }

            return("");
        }
Example #45
0
        public ulong GetDecryptionKey(string strMessage)
        {
            ArmorTypes atType = new ArmorTypes();
            string strRest = "";
            string strRadix64 = Armor.RemoveArmor(strMessage, ref atType, ref strRest);
            if (strRadix64.Length == 0)
                throw new Exception("This is not a valid OpenPGP message!");

            EncryptedMessage emMessage = new EncryptedMessage();
            Packet[] pPackets = Packet.ParsePackets(strRadix64);

            emMessage.ParseMessage(pPackets);

            if (!emMessage.SymmetricallyEncrypted) {
                ulong lKeyID = emMessage.GetFittingKeyID(skrKeyRing);
                return lKeyID;
            } else
                return 0ul;
        }