public static T CreateDesignData <T>(params string[] propertyValues) where T : class { if (typeof(T).Name.Contains("EcKeyPairInfo")) { var seed = Encoding.UTF8.GetBytes(propertyValues.Aggregate((s, s1) => s + s1)); seed = SHA1.Create().ComputeHash(seed); var key = ToHexString(seed); if (!KeyStorage.ContainsKey(key)) { KeyStorage.Add(key, EncryptionSuite.Encryption.EllipticCurveCryptographer.CreateKeyPair(false)); } return(new EncryptionSuite.Contract.EcKeyPairInfo() { TokenLabel = propertyValues[1], ManufacturerId = "Nitrokey", CurveDescription = "brainpoolP320r1 (320 bit)", ECParamsData = StringToByteArray("06092b2403030208010109"), PublicKey = KeyStorage[key], EcIdentifier = new EcIdentifier() { KeyLabel = propertyValues[0], TokenSerialNumber = propertyValues[2] } } as T); } return(default(T)); }
private void AddToKeyStorage(string strKey, string strValue) { if (!KeyStorage.ContainsKey(strKey)) { KeyStorage.Add(strKey, strValue); } else { KeyStorage[strKey] = strValue; } }
private void DoActions(GameAction[] actions) { if (actions == null) { return; } for (int i = 0; i < actions.Length; ++i) { if (actions[i].Type == ActionType.FindKey) { KeyStorage.Add(actions[i].KeyNumber); } else if (actions[i].Type == ActionType.LoseKey) { KeyStorage.Remove(actions[i].KeyNumber); } } }
public static void Main(string[] args, KeyStorage keyStorage) { Console.WriteLine("Keys"); if (args.Length == 1) { Console.WriteLine(); Console.WriteLine("Public keys:"); foreach (PublicKey pub in keyStorage.PublicKeys) { Console.WriteLine(" " + pub); } Console.WriteLine(); Console.WriteLine("Private keys:"); foreach (PrivateKey priv in keyStorage.PrivateKeys) { Console.WriteLine(" " + priv.ToString()); } Console.WriteLine(); return; } if (args.Length == 3 && args [1] == "generate") { PrivateKey key = PrivateKey.Generate(); string name = Path.GetFileName(args [2]); keyStorage.Add(name, key); Console.WriteLine(); Console.WriteLine("New key: " + name); Console.WriteLine(key.ToString()); Console.WriteLine(); return; } throw new HelpException("Missing arguments"); }