/// <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));
/// <summary> /// Encrypt data with the specified key, and return the result. /// </summary> /// <param name="sourceData">A byte array with the source data.</param> /// <param name="useSharedKey">Whether to use the Zymbit cloud key.</param> /// <returns>The encrypted data.</returns> public byte[] LockData(byte[] sourceData, bool useSharedKey = false) { NativeHelper.Validate(NativeMethods.zkLockDataB2B(_ref, sourceData, sourceData.Length, out var output, out var outputLen, useSharedKey)); return(NativeHelper.PtrToArray(output, outputLen)); }
/// <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));
/// <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));
/// <summary> /// Encrypt data from a file with the specified key, and return the result. /// </summary> /// <param name="sourceFile">The source filename.</param> /// <param name="useSharedKey">Whether to use the Zymbit cloud key.</param> /// <returns>The encrypted data.</returns> public byte[] LockData(string sourceFile, bool useSharedKey = false) { NativeHelper.Validate(NativeMethods.zkLockDataF2B(_ref, sourceFile, out var output, out var outputLen, useSharedKey)); return(NativeHelper.PtrToArray(output, outputLen)); }
/// <summary> /// Gets the perimeter detection info. /// </summary> /// <returns>The info as an array of ints.</returns> public int[] GetPerimeterDetectInfo() { NativeHelper.Validate(NativeMethods.zkGetPerimeterDetectInfo(_ref, out IntPtr info, out var infoCount)); return(NativeHelper.PtrToArrayInt(info, (int)infoCount)); }
/// <summary> /// Clears the perimeter detection info and rearms all channels. /// </summary> public void ClearPerimeterDetectEvents() => NativeHelper.Validate(NativeMethods.zkClearPerimeterDetectEvents(_ref));
/// <summary> /// Disposes the Zymkey context. /// </summary> public void Dispose() { NativeHelper.Validate(NativeMethods.zkClose(_ref)); }
/// <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));
/// <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));
/// <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));
/// <summary> /// Turns the hardware LED on. /// </summary> public void LedOn() => NativeHelper.Validate(NativeMethods.zkLEDOn(_ref));
/// <summary> /// Return the ECDSA public key at the specified slot. /// </summary> /// <param name="slot">The Zymkey slot.</param> /// <returns>The ECDSA public key.</returns> public byte[] GetEcdsaPubkey(int slot = 0) { NativeHelper.Validate(NativeMethods.zkGetECDSAPubKey(_ref, out var publicKey, out var publicKeyLen, slot)); return(NativeHelper.PtrToArray(publicKey, publicKeyLen)); }
/// <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));
/// <summary> /// Opens a new Zymkey context. /// </summary> public Zymkey() { NativeHelper.Validate(NativeMethods.zkOpen(out _ref)); }
/// <summary> /// Generate an ECDSA signature from a digest. /// </summary> /// <param name="digest">The digest to sign.</param> /// <param name="slot">The Zymkey key slot to use for the operation.</param> /// <returns>The ECDSA signature.</returns> public byte[] GenerateEcdsaSignatureFromDigest(byte[] digest, int slot = 0) { NativeHelper.Validate(NativeMethods.zkGenECDSASigFromDigest(_ref, digest, slot, out var output, out var outputLen)); return(NativeHelper.PtrToArray(output, outputLen)); }