/// <summary> /// Loads a keyring file /// </summary> /// <param name="strPath">The keyring file location</param> 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[] tpkKeys = TransportablePublicKey.SplitKeys(strKey); foreach (TransportablePublicKey tpkKey in tpkKeys) { this.Add(tpkKey); } strKey = Armor.RemoveArmor(strKeys, ref atType, ref strKeys); } this.bIsUpdated = false; }
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!"); } }