Beispiel #1
0
        public virtual void DoTest2()
        {
            RsaKeyParameters pubParameters  = new RsaKeyParameters(false, mod1, pub1);
            RsaKeyParameters privParameters = new RsaKeyParameters(true, mod1, pri1);
            RsaEngine        rsa            = new RsaEngine();

            byte[] data;

            //
            // ISO 9796-1 - public encrypt, private decrypt
            //
            ISO9796d1Encoding eng = new ISO9796d1Encoding(rsa);

            eng.Init(true, privParameters);

            data = eng.ProcessBlock(msg2, 0, msg2.Length);

            eng.Init(false, pubParameters);

            if (!IsSameAs(data, 1, sig2))
            {
                Fail("failed ISO9796-1 generation Test 2");
            }

            data = eng.ProcessBlock(data, 0, data.Length);

            if (!AreEqual(msg2, data))
            {
                Fail("failed ISO9796-1 retrieve Test 2");
            }
        }
Beispiel #2
0
        public virtual void DoTest3()
        {
            RsaKeyParameters pubParameters  = new RsaKeyParameters(false, mod2, pub2);
            RsaKeyParameters privParameters = new RsaKeyParameters(true, mod2, pri2);
            RsaEngine        rsa            = new RsaEngine();

            byte[] data;

            //
            // ISO 9796-1 - public encrypt, private decrypt
            //
            ISO9796d1Encoding eng = new ISO9796d1Encoding(rsa);

            eng.Init(true, privParameters);

            eng.SetPadBits(4);

            data = eng.ProcessBlock(msg3, 0, msg3.Length);

            eng.Init(false, pubParameters);

            if (!IsSameAs(sig3, 1, data))
            {
                Fail("failed ISO9796-1 generation Test 3");
            }

            data = eng.ProcessBlock(data, 0, data.Length);

            if (!IsSameAs(msg3, 0, data))
            {
                Fail("failed ISO9796-1 retrieve Test 3");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Generate cipher. The cipher can be reused.
        /// </summary>
        /// <param name="padding">Asymmetric algorithm padding mode.</param>
        /// <param name="asymmetricKey">Asymmetric public key or private key.</param>
        /// <returns></returns>
        /// <exception cref="Exception"/>
        public IAsymmetricBlockCipher GenerateCipher(AsymmetricPaddingMode padding, AsymmetricKeyParameter asymmetricKey)
        {
            IAsymmetricBlockCipher cipher = new RsaBlindedEngine();

            switch (padding)
            {
            case AsymmetricPaddingMode.NoPadding: break;

            case AsymmetricPaddingMode.PKCS1: cipher = new Pkcs1Encoding(cipher); break;

            case AsymmetricPaddingMode.OAEP: cipher = new OaepEncoding(cipher); break;

            case AsymmetricPaddingMode.ISO9796_1: cipher = new ISO9796d1Encoding(cipher); break;

            default: throw new System.Security.Cryptography.CryptographicException("Unsupported padding mode.");
            }
            cipher.Init(!asymmetricKey.IsPrivate, asymmetricKey);
            return(cipher);
        }