Exemple #1
0
        public void testRsaDecryption()
        {
            /* foreach */
            foreach (TpmBackEnd tpm  in  backEndList)
            {
                // Create an rsa key.
                Name identityName = new Name("/Test/KeyName");

                TpmKeyHandle key     = tpm.createKey(identityName, new RsaKeyParams());
                Name         keyName = key.getKeyName();

                Blob content = new Blob(new int[] { 0x01, 0x02, 0x03, 0x04 });

                Blob publicKey = key.derivePublicKey();

                // TODO: Move encrypt to PublicKey?
                Blob cipherText = net.named_data.jndn.encrypt.algo.RsaAlgorithm.encrypt(publicKey, content,
                                                                                        new EncryptParams(net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.RsaOaep));

                Blob plainText = key.decrypt(cipherText.buf());

                Assert.AssertTrue(plainText.equals(content));

                tpm.deleteKey(keyName);
                Assert.AssertEquals(false, tpm.hasKey(keyName));
            }
        }
Exemple #2
0
        public void testRandomKeyId()
        {
            TpmBackEnd tpm = backEndMemory;

            Name identityName = new Name("/Test/KeyName");

            HashedSet <Name> keyNames = new HashedSet <Name>();

            for (int i = 0; i < 100; i++)
            {
                TpmKeyHandle key     = tpm.createKey(identityName, new RsaKeyParams());
                Name         keyName = key.getKeyName();
                Assert.AssertTrue(ILOG.J2CsMapping.Collections.Collections.Add(keyNames, keyName));
            }
        }
Exemple #3
0
        public void testRsaSigning()
        {
            /* foreach */
            foreach (TpmBackEnd tpm  in  backEndList)
            {
                // Create an RSA key.
                Name identityName = new Name("/Test/KeyName");

                TpmKeyHandle key     = tpm.createKey(identityName, new RsaKeyParams());
                Name         keyName = key.getKeyName();

                Blob content   = new Blob(new int[] { 0x01, 0x02, 0x03, 0x04 });
                Blob signature = key.sign(net.named_data.jndn.security.DigestAlgorithm.SHA256, content.buf());

                Blob publicKey = key.derivePublicKey();

                bool result = net.named_data.jndn.security.VerificationHelpers.verifySignature(content,
                                                                                               signature, publicKey);
                Assert.AssertEquals(true, result);

                tpm.deleteKey(keyName);
                Assert.AssertEquals(false, tpm.hasKey(keyName));
            }
        }