public string Get() { var stopwatch = new Stopwatch(); stopwatch.Start(); var hashingKey = new byte[32]; var encryptionKey = new byte[32]; using (var provider = new RNGCryptoServiceProvider()) { provider.GetBytes(hashingKey); provider.GetBytes(encryptionKey); } var nonceGenerator = new NonceGenerator(); nonceGenerator.Execute(); var armorToken = new ArmorToken("*****@*****.**", "HMH", nonceGenerator.Nonce); var hash = new HashArmorTokenGenerationStep(new HMACSHA256HashingMechanismFactory(hashingKey), new EmptyArmorTokenGenerationStep()); var encrypt = new EncryptArmorTokenGenerationStep(new RijndaelEncryptionMechanismFactory(encryptionKey), hash); var serialise = new SerialiseArmorTokenGenerationStep(new ArmorTokenSerialisor(), encrypt); var armorTokenGenerator = new ArmorTokenGenerator(armorToken, serialise); armorTokenGenerator.Execute(); stopwatch.Stop(); Trace.WriteLine(string.Concat("Time: ", stopwatch.ElapsedMilliseconds)); return(armorTokenGenerator.ArmorToken); }
public override void Encrypt() { var encrypt = new EncryptArmorTokenGenerationStep(new RijndaelEncryptionMechanismFactory(encryptionKey)); encrypt.Generate(SecureArmorToken); SecureArmorToken = (string)encrypt.ArmorTokenGenerationStepResult.Output; }
public void WhenIHaveGeneratedTheArmorToken() { using (var provider = new RNGCryptoServiceProvider()) { provider.GetBytes(encryptionKey); provider.GetBytes(hashingKey); } var step3 = new HashArmorTokenGenerationStep(new HMACSHA512HashingMechanismFactory(hashingKey), new EmptyArmorTokenGenerationStep()); var step2 = new EncryptArmorTokenGenerationStep(new RijndaelEncryptionMechanismFactory(encryptionKey), step3); var step1 = new SerialiseArmorTokenGenerationStep(new ArmorTokenSerialisor(), step2); var armorTokenGenerator = new ArmorTokenGenerator(armorToken, step1); armorTokenGenerator.Execute(); hashedArmorToken = armorTokenGenerator.ArmorToken; }