/// <summary> /// Signs some bytes. /// </summary> /// <returns>The singed byte array.</returns> /// <param name="toSign">The bytes to sign</param> /// <param name="signKeyPair">KeyPair to sign the bytes with.</param> public static byte[] SignByteDetached(byte[] toSign, KeyPair signKeyPair) { byte[] signature = new byte[CRYPTO_SIGN_BYTES]; long signatureLength = signature.Length; long toSingLength = toSign.Length; NativeLibsodium.crypto_sign_detached(signature, ref signatureLength, toSign, toSingLength, signKeyPair.secretKey); return(signature); }
public byte[] GetSignatureBytes(byte[] msg) { if (keyPair == null) { Debug.LogError("Key pair not initialized"); return(null); } if (msg == null) { Debug.LogError("Msg cannot be null"); return(null); } byte[] sig = new byte[64]; long sigLen = 0; try { if (lastMsgBytes != msg) { Debug.LogWarning("Warning msg does not match:"); Debug.LogWarning(Encoding.ASCII.GetString(msg)); } Debug.Log($"signing message of len {msg.Length} with sk of: {GetSK()}"); if (NativeLibsodium.crypto_sign_detached(sig, ref sigLen, msg, msg.Length, keyPair.skBytes) == 0) { lastMsgBytes = msg; return(sig); } } catch (Exception ex) { Debug.LogError("Error generating signature: " + ex.Message); } return(null); }