public void TestSecretKeyWrapperRoundTrip()
        {
            var secretKeyWrapper = new SecretKeyWrapper(context, UnitTestAlias);
            var secretKeys       = AesCbcWithIntegrity.GenerateKey();
            var wrappedKey       = secretKeyWrapper.EncryptedThenMac(secretKeys);

            Assert.False(AesCbcWithIntegrity.KeyString(secretKeys) == wrappedKey);

            var unwrappedKey = secretKeyWrapper.CheckMacAndDecrypt(wrappedKey);

            Assert.True(AesCbcWithIntegrity.KeyString(secretKeys) == AesCbcWithIntegrity.KeyString(unwrappedKey));
        }
Beispiel #2
0
        public string EncryptedThenMac(AesCbcWithIntegrity.SecretKeys keys)
        {
            cipher.Init(CipherMode.EncryptMode, pair.Public);
            var cipherText = cipher.DoFinal(Encoding.UTF8.GetBytes(AesCbcWithIntegrity.KeyString(keys)));

            Signature s = Signature.GetInstance(HmacAlgorithm);

            s.InitSign(pair.Private);
            s.Update(cipherText);
            byte [] signature = s.Sign();


            return(string.Format("{0}:{1}", Convert.ToBase64String(signature), Convert.ToBase64String(cipherText)));
        }