示例#1
0
        public static int ImportCspBlob(byte[] importedKeyBytes, SafeProvHandleImpl providerHandle, SafeKeyHandleImpl publicKeyHandle, out SafeKeyHandleImpl keyExchangeHandle)
        {
            var dwFlags        = MapCspKeyFlags(CspProviderFlags.NoFlags);
            var keyExchangeRef = SafeKeyHandleImpl.InvalidHandle;

            if (!CryptoApi.CryptImportKey(providerHandle, importedKeyBytes, (uint)importedKeyBytes.Length, publicKeyHandle, dwFlags, ref keyExchangeRef))
            {
                throw CreateWin32Error();
            }

            var keyNumberMask = BitConverter.ToInt32(importedKeyBytes, 4) & 0xE000;
            var keyNumber     = (keyNumberMask == 0xA000) ? Constants.AT_KEYEXCHANGE : Constants.AT_SIGNATURE;

            keyExchangeHandle = keyExchangeRef;

            return(keyNumber);
        }