Esempio n. 1
0
        public static PlainText Decrypt(this string textToEncrypt)
        {
            var encryptionKey = AppInstance.Instance.ApiAssets[Constants.ASSET_ADMIN_ENCRYPTIONKEY];
            var encryptedText = new EncryptedText(textToEncrypt);

            return(encryptedText.Decrypt(encryptionKey));
        }
    public byte[] SerializeEncryptedText(CipherAlgorithm algorithm, string clearText)
    {
        var encodedBytes = new EncryptedText(algorithm,
                                             clearText,
                                             TestFakeSigner.FixedKeysInstance,
                                             TestFakeSigner.FixedKeysInstance,
                                             Array.Empty <TagReader>()).AsPayload.EncodedBytes;

        TestContext.WriteLine(encodedBytes.AsLiteral());
        return(encodedBytes.PartOf(124));
    }
Esempio n. 3
0
        public void Do_Ivs_Have_the_same_length()
        {
            string key = "eguhidbehumjdemy";

            Assert.AreEqual(16, key.Length);

            var srv = new DpapiCryptographyService();

            EncryptedText result  = srv.Encrypt("");
            EncryptedText result2 = srv.Encrypt("2024");
            EncryptedText result3 = srv.Encrypt("stnaoheutnahoetuhatnoeuhaonetuhnsaoteuh");

            string s = result2.Iv + result2.CipherText;

            Assert.AreEqual(32, result.Iv.Length);
            Assert.AreEqual(32, result2.Iv.Length);
            Assert.AreEqual(32, result3.Iv.Length);
        }
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var encryptedText = EncryptedText.Get(context);

            ///////////////////////////
            // Add execution logic HERE

            string password  = "******";
            string plainText = Cipher.Decrypt(encryptedText, password);

            ///////////////////////////

            // Outputs
            return((ctx) => {
                PlainText.Set(ctx, plainText);
            });
        }
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var encryptionAlgorithm = EncryptionAlgorithm;
            var encryptedText       = EncryptedText.Get(context);

            string plainText = null;

            ///////////////////////////
            // Add execution logic HERE
            string password = "******";

            //Select algorithm
            switch (EncryptionAlgorithm)
            {
            //SHA256
            case enumEncryptType.SHA256:
                plainText = Cipher.Decrypt(encryptedText, password);
                break;

            //AES
            case enumEncryptType.AES:
                plainText = AES.DecryptStringAES(encryptedText, password);
                break;

            //HMAC
            case enumEncryptType.HMAC:
                plainText = HMAC.SimpleDecryptWithPassword(encryptedText, password);
                break;

            //ASCIII
            case enumEncryptType.ASCIII:
                plainText = ASCIII.Decrypt(encryptedText);
                break;
            }

            // Outputs
            return((ctx) =>
            {
                PlainText.Set(ctx, plainText);
            });
        }
Esempio n. 6
0
        private string DecryptTextFile()
        {
            UnicodeEncoding uniencoding   = new UnicodeEncoding();
            StringBuilder   decryptedText = new StringBuilder();

            char[] encryptedTextChars = EncryptedText.ToCharArray();
            char[] decryptedChars     = new char[encryptedTextChars.Length];
            char[] password           = Password.ToCharArray();
            int    index                = 0;
            int    keyCarret            = 1;
            int    tmpCharNumber        = -1;
            int    tmpKeyCharNumber     = -1;
            int    tmpCryptedCharNumber = -1;

            foreach (var c in encryptedTextChars)
            {
                if (alphabet.ContainsKey(c))
                {
                    tmpCharNumber        = alphabet[c];
                    tmpKeyCharNumber     = alphabet[password[keyCarret % password.Length]];
                    tmpCryptedCharNumber = (tmpCharNumber - tmpKeyCharNumber);

                    if (tmpCryptedCharNumber < 1)
                    {
                        tmpCryptedCharNumber += alphabet.Count;
                    }
                    decryptedChars[index] = GetKeyByValue(tmpCryptedCharNumber);
                }
                else
                {
                    decryptedChars[index] = c;
                }
                ++index;
            }
            return(decryptedText.Append(decryptedChars).ToString());
        }
Esempio n. 7
0
 public EncryptedKindEntity(EncryptedText name)
 {
     Value = name;
 }
Esempio n. 8
0
        public static PlainText Decrypt(this EncryptedText encryptedText, string encryptionKey)
        {
            var decryptedText = Crypto.Decrypt(encryptedText.Value, encryptionKey);

            return(new PlainText(decryptedText));
        }
        public SubstitutionAttacker(
            string encryptedText,
            int individualSetMembersCount,
            int minPopulationSize,
            int maxPopulationSize,
            int iterationsCount,
            double mutationPercentage,
            int bestPercentage,
            List <EtalonMember> twoLettersFrequencies,
            List <EtalonMember> threeLettersFrequencies,
            double twoLettersFittingQuotientCoef   = 1,
            double threeLettersFittingQuotientCoef = 1)
        {
            EncryptedText = encryptedText ?? throw new ArgumentNullException(nameof(encryptedText));
            EncryptedText = EncryptedText.ToLower();

            if (individualSetMembersCount <= 0)
            {
                throw new ArgumentException($"{nameof(individualSetMembersCount)} must be  greather than 0");
            }
            IndividualSetMembersCount = individualSetMembersCount;

            if (minPopulationSize <= 0)
            {
                throw new ArgumentException($"{nameof(minPopulationSize)} must be  greather than 0");
            }
            MinPopulationSize = minPopulationSize;

            if (maxPopulationSize <= 0)
            {
                throw new ArgumentException($"{nameof(maxPopulationSize)} must be  greather than 0");
            }
            MaxPopulationSize = maxPopulationSize;

            if (minPopulationSize > maxPopulationSize)
            {
                throw new ArgumentException($"{nameof(maxPopulationSize)} must be equal to or greather than {nameof(minPopulationSize)}");
            }

            if (iterationsCount <= 0)
            {
                throw new ArgumentException($"{nameof(iterationsCount)} must be  greather than 0");
            }
            IterationsCount = iterationsCount;

            if (mutationPercentage <= 0 || mutationPercentage > 100)
            {
                throw new ArgumentException($"{nameof(mutationPercentage)} must be value from 0 to 100");
            }
            MutationPercentage = mutationPercentage;

            if (bestPercentage <= 0 || bestPercentage > 100)
            {
                throw new ArgumentException($"{nameof(bestPercentage)} must be value from 0 to 100");
            }
            BestPercentage = bestPercentage;

            _twoLettersFrequencies   = twoLettersFrequencies ?? throw new ArgumentNullException(nameof(twoLettersFrequencies));
            _threeLettersFrequencies = threeLettersFrequencies ?? throw new ArgumentNullException(nameof(threeLettersFrequencies));

            Alphabet = new string(SingleByteXorAttacker.OneLetterEnglishFrequency.Select(c => c.Key).ToArray());

            TwoLettersFittingQuotientCoef   = twoLettersFittingQuotientCoef;
            ThreeLettersFittingQuotientCoef = threeLettersFittingQuotientCoef;
        }