private void bulkTest(PrivateKeyManager privateKey, CertificateX509 cert, string hashAlgorithm)
        {
            string enc = Global.GLOBAL_ENCODING;

            if (SecurityUtils.compareStrings(enc, "UTF_32") || SecurityUtils.compareStrings(enc, "UTF_32BE") ||
                SecurityUtils.compareStrings(enc, "UTF_32LE"))
            {
                plainText = eu.getString(eu.getBytes(plainText32));
            }
            else
            {
                plainText = eu.getString(eu.getBytes(plainText16));
            }

            for (int p = 0; p < arrayPaddings.Length; p++)
            {
                AsymmetricCipher asymCipher = new AsymmetricCipher();
                // AsymmetricCipher asymCipherD = new AsymmetricCipher();
                string encrypted1 = asymCipher.DoEncrypt_WithPrivateKey(hashAlgorithm, arrayPaddings[p], privateKey,
                                                                        plainText);
                string decrypted1 = asymCipher.DoDecrypt_WithPublicKey(hashAlgorithm, arrayPaddings[p], cert, encrypted1);

                Assert.AreEqual(decrypted1, plainText);
                True(SecurityUtils.compareStrings(decrypted1, plainText), asymCipher);
                string encrypted2 = asymCipher.DoEncrypt_WithPublicKey(hashAlgorithm, arrayPaddings[p], cert, plainText);
                string decrypted2 = asymCipher.DoDecrypt_WithPrivateKey(hashAlgorithm, arrayPaddings[p], privateKey,
                                                                        encrypted2);
                Assert.IsTrue(SecurityUtils.compareStrings(decrypted2, plainText));
                True(SecurityUtils.compareStrings(decrypted2, plainText), asymCipher);
            }
        }
Ejemplo n.º 2
0
        public void TestSpaces()
        {
            key.Load(pathKey);
            cert.Load(pathCert);
            string encrypted1 = asymCipher.DoEncrypt_WithPrivateKey("SHA1 ", "PCKS1PADDING ", key, plainText);

            //System.out.println("Error. Code: " + asymCipher.getErrorCode() + " Desc: " + asymCipher.getErrorDescription());
            Assert.IsFalse(asymCipher.HasError());

            string decrypted = asymCipher.DoDecrypt_WithPublicKey(" SHA1", " PCKS1PADDING", cert, encrypted1);

            Assert.IsFalse(asymCipher.HasError());
            Assert.IsTrue(SecurityUtils.compareStrings(plainText, decrypted));
        }