Пример #1
0
        /// <summary>
        /// Gets an array of random bytes.
        /// </summary>
        /// <param name="length">The number of bytes to generate.</param>
        public byte[] GetRandomBytes(int length)
        {
            var bytes = new byte[length];

            NativeHelper.Validate(NativeMethods.zkGetRandBytes(_ref, bytes, length));
            return(bytes);
        }
Пример #2
0
        /// <summary>
        /// Verify an ECDSA signature from a digest with a foreign key.
        /// </summary>
        /// <param name="digest">The digest to verify.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="foreignPubkey">The foreign key.</param>
        /// <param name="der">Whether the signature is DER.</param>
        /// <param name="pubkeyType">Type of curve to verify against.</param>
        /// <returns>Whether the signature is valid.</returns>
        public bool VerifyEcdsaSignatureFromDigest(byte[] digest, byte[] signature, byte[] foreignPubkey, bool der = false, ZkForeignPubkeyType pubkeyType = ZkForeignPubkeyType.NistP256)
        {
            var code = NativeMethods.zkVerifyECDSASigFromDigestWithForeignKey(_ref, digest, foreignPubkey, foreignPubkey.Length, signature, signature.Length, der, pubkeyType);

            NativeHelper.Validate(code);

            return(code == 1 ? true : false);
        }
Пример #3
0
        /// <summary>
        /// Verify an ECDSA signature from a digest.
        /// </summary>
        /// <param name="digest">The digest to verify.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="slot">The Zymkey key slot to use for the operation.</param>
        /// <returns>Whether the signature is valid.</returns>
        public bool VerifyEcdsaSignatureFromDigest(byte[] digest, byte[] signature, int slot = 0)
        {
            var code = NativeMethods.zkVerifyECDSASigFromDigest(_ref, digest, slot, signature, signature.Length);

            NativeHelper.Validate(code);

            return(code == 1 ? true : false);
        }
Пример #4
0
        /// <summary>
        /// Blocks until a perimeter event is triggered or the timeout is reached.
        /// </summary>
        /// <param name="timeout">The timeout in milliseconds.</param>
        /// <returns>Whether the event was triggered.</returns>
        public bool WaitForPerimeterEvent(uint timeout)
        {
            var code = NativeMethods.zkWaitForPerimeterEvent(_ref, timeout);

            if (code == -NativeMethods.ETIMEDOUT)
            {
                return(false);
            }

            NativeHelper.Validate(code);
            return(true);
        }
Пример #5
0
 /// <summary>
 /// Decrypt data with the specified key, and store the result in a file.
 /// </summary>
 /// <param name="sourceData">A byte array with the source data.</param>
 /// <param name="destFile">The destination filename.</param>
 /// <param name="useSharedKey">Whether to use the Zymbit cloud key.</param>
 public void UnlockData(byte[] sourceData, string destFile, bool useSharedKey = false)
 => NativeHelper.Validate(NativeMethods.zkUnlockDataB2F(_ref, sourceData, sourceData.Length, destFile, useSharedKey));
Пример #6
0
 /// <summary>
 /// Decrypt data from a file with the specified key, and store the result in a file.
 /// </summary>
 /// <param name="sourceFile">The source filename.</param>
 /// <param name="destFile">The destination filename.</param>
 /// <param name="useSharedKey">Whether to use the Zymbit cloud key.</param>
 public void UnlockData(string sourceFile, string destFile, bool useSharedKey = false)
 => NativeHelper.Validate(NativeMethods.zkUnlockDataF2F(_ref, sourceFile, destFile, useSharedKey));
Пример #7
0
 /// <summary>
 /// Sets the action taken when a perimeter channel is tripped.
 /// </summary>
 /// <param name="channel">The channel to set.</param>
 /// <param name="actionFlags">Bitfield of the action(s) to take.</param>
 public void SetPerimeterEventAction(int channel, uint actionFlags)
 => NativeHelper.Validate(NativeMethods.zkSetPerimeterEventAction(_ref, channel, actionFlags));
Пример #8
0
 /// <summary>
 /// Clears the perimeter detection info and rearms all channels.
 /// </summary>
 public void ClearPerimeterDetectEvents()
 => NativeHelper.Validate(NativeMethods.zkClearPerimeterDetectEvents(_ref));
Пример #9
0
 /// <summary>
 /// Sets the sensitivity of tap operations.
 /// </summary>
 /// <param name="axis">The axis to configure.</param>
 /// <param name="sensitivity">The sensitivity, expressed as a percentage.</param>
 public void SetTapSensitivity(ZkAccelAxisType axis, float sensitivity)
 => NativeHelper.Validate(NativeMethods.zkSetTapSensitivity(_ref, axis, sensitivity));
Пример #10
0
 /// <summary>
 /// Disposes the Zymkey context.
 /// </summary>
 public void Dispose()
 {
     NativeHelper.Validate(NativeMethods.zkClose(_ref));
 }
Пример #11
0
 /// <summary>
 /// Sets the Zymkey's I2C address.
 /// </summary>
 /// <param name="addr">The I2C address.</param>
 public void SetI2CAddr(int addr)
 => NativeHelper.Validate(NativeMethods.zkSetI2CAddr(_ref, addr));
Пример #12
0
 /// <summary>
 /// Flashes the hardware LED for the specified times.
 /// </summary>
 /// <param name="on">The time the LED will stay on.</param>
 /// <param name="off">The time the LED will stay off.</param>
 /// <param name="numFlashes">The number of times to flash. If 0, the LED will flash indefinitely.</param>
 public void LedFlash(uint on, uint off = 0, uint numFlashes = 0)
 => NativeHelper.Validate(NativeMethods.zkLEDFlash(_ref, on, off, numFlashes));
Пример #13
0
 /// <summary>
 /// Turns the hardware LED on.
 /// </summary>
 public void LedOn()
 => NativeHelper.Validate(NativeMethods.zkLEDOn(_ref));
Пример #14
0
 /// <summary>
 /// Save the ECDSA public key at the specified slot to a file.
 /// </summary>
 /// <param name="destFile">The file to save to.</param>
 /// <param name="slot">The Zymkey slot.</param>
 public void SaveEcdsaPubkeyToFile(string destFile, int slot = 0)
 => NativeHelper.Validate(NativeMethods.zkSaveECDSAPubKey2File(_ref, destFile, slot));
Пример #15
0
 /// <summary>
 /// Opens a new Zymkey context.
 /// </summary>
 public Zymkey()
 {
     NativeHelper.Validate(NativeMethods.zkOpen(out _ref));
 }