Exemple #1
0
        public BigInteger ExportPrivateKey()
        {
            var context = GetHandle(_cert);

            var derive = new KeyDerivation();

            derive.Init();

            byte[] sessKey, privKeyBlob;
            ExportPrivateKey(context, derive.GetPublicKeyBytes(), out sessKey, out privKeyBlob);

            _encryptedPkey = new EncryptedPrivateKey(privKeyBlob);
            _sk            = new SessionKey(sessKey);
            var kek  = derive.Vko(_encryptedPkey, _sk.GetPublicKey());
            var pkey = _encryptedPkey.UnwrapKey(kek);

            Array.Reverse(pkey);

            return(new BigInteger(1, pkey));
        }
Exemple #2
0
        public BigInteger ExportPrivateKey()
        {
            var pkeyInfo = GetPrivateKeyInfo(_cert);

            CheckProvider(pkeyInfo);
            var provType = (ProviderType)pkeyInfo.ProviderType;
            var factory  = KeyExportFactory.Create(provType);

            var derive      = factory.CreateKeyDerivation();
            var blob        = factory.CreatePrivateKeyBlob();
            var privKeyBlob = blob.GetPrivateKeyBlob(_cert.Handle, derive);

            _encryptedPkey = factory.CreateEncryptedPrivateKey(privKeyBlob);
            _sk            = factory.CreateSessionKey(blob.SessionKey);
            var kek  = derive.Vko(_encryptedPkey, _sk.GetPublicKey());
            var pkey = _encryptedPkey.UnwrapKey(kek);

            Array.Reverse(pkey);

            return(new BigInteger(1, pkey));
        }