public void Constructor1_ValidParams_Sucess(string modularCryptFormatStr,
                                             char   expectedDelim,
                                             string expectedIdentifier,
                                             int    expectedWorkFactor,
                                             string expectedSaltAsBase64,
                                             string expectedCipherAsBase64)
 {
     var mc = new ModularCrypt(modularCryptFormatStr);
     Assert.AreEqual(expectedDelim,                                    mc.Delim);
     Assert.AreEqual(expectedIdentifier,                               mc.Identifier);
     Assert.AreEqual(expectedWorkFactor,                               mc.WorkFactor);
     Assert.AreEqual(Convert.FromBase64String(expectedSaltAsBase64),   mc.Salt);
     Assert.AreEqual(Convert.FromBase64String(expectedCipherAsBase64), mc.Cipher);
     Assert.AreEqual(modularCryptFormatStr,                            mc.ToString());
 }
Beispiel #2
0
        public byte[] Decrypt(ModularCrypt modularCrypt)
        {
            IEncryptionService encryptionService;

            try
            {
                encryptionService = _encryptionServices[modularCrypt.Identifier];
            }
            catch (KeyNotFoundException)
            {
                throw new NotSupportedException("No IEncryptionService with the identifier " + modularCrypt.Identifier + " configured.");
            }

            return(encryptionService.Decrypt(modularCrypt.Cipher,
                                             modularCrypt.WorkFactor,
                                             modularCrypt.Salt));
        }
Beispiel #3
0
        public ModularCrypt Encrypt(byte[]       unencrypted,
                                    ModularCrypt modularCrypt)
        {
            IEncryptionService encryptionService;

            try
            {
                encryptionService = _encryptionServices[modularCrypt.Identifier];
            }
            catch (KeyNotFoundException)
            {
                throw new NotSupportedException("No IEncryptionService with the identifier " + modularCrypt.Identifier + " configured.");
            }

            byte[] encrypted = encryptionService.Encrypt(unencrypted,
                                                         modularCrypt.WorkFactor,
                                                         modularCrypt.Salt);

            return(new ModularCrypt(_modularCryptDelim,
                                    modularCrypt.Identifier,
                                    modularCrypt.WorkFactor,
                                    modularCrypt.Salt,
                                    encrypted));
        }
Beispiel #4
0
        public ModularCrypt Hash(byte[]       data,
                                 ModularCrypt modularCrypt)
        {
            IHashingService hashingService;

            try
            {
                hashingService = _hashingServices[modularCrypt.Identifier];
            }
            catch (KeyNotFoundException)
            {
                throw new NotSupportedException("No IHashingService with the identifier " + modularCrypt.Identifier + " configured.");
            }

            byte[] hash = hashingService.Hash(data,
                                              modularCrypt.WorkFactor,
                                              modularCrypt.Salt);

            return(new ModularCrypt(_modularCryptDelim,
                                    modularCrypt.Identifier,
                                    modularCrypt.WorkFactor,
                                    modularCrypt.Salt,
                                    hash));
        }
        public void Constructor2_ValidParams_Sucess(char   delim,
                                                    string identifier,
                                                    int    workFactor,
                                                    string saltAsBase64,
                                                    string cipherAsBase64,
                                                    string expectedToString)
        {
            byte[] salt   = saltAsBase64   == null ? null : Convert.FromBase64String(saltAsBase64);
            byte[] cipher = cipherAsBase64 == null ? null : Convert.FromBase64String(cipherAsBase64);

            var mc = new ModularCrypt(delim,
                                      identifier,
                                      workFactor,
                                      salt,
                                      cipher);

            Assert.AreEqual(delim,            mc.Delim);
            Assert.AreEqual(identifier,       mc.Identifier);
            Assert.AreEqual(workFactor,       mc.WorkFactor);
            Assert.AreEqual(salt,             mc.Salt);
            Assert.AreEqual(cipher,           mc.Cipher);
            Assert.AreEqual(expectedToString, mc.ToString());
        }
Beispiel #6
0
 public bool Equals(ModularCrypt value)
 {
     return(Equals((object)value));
 }
Beispiel #7
0
 public bool Equals(ModularCrypt value)
 {
     return Equals((object)value);
 }