public byte[] SignOpenMessage(byte[] signedVar)
    {
        byte[] value       = new byte[signedVar.Length - 64];
        long   valueLength = value.LongLength;

        NativeLibsodium.crypto_sign_open(value, ref valueLength, signedVar, signedVar.LongLength,
                                         System.Convert.FromBase64String(ChaChaSigPublicKey));
        return(value);
    }
    public byte[] SignOpenMessage(byte[] signed)
    {
        byte[] buffer       = new byte[100000];
        long   bufferLength = 0;

        NativeLibsodium.crypto_sign_open(buffer, ref bufferLength, signed, signed.Length, Convert.FromBase64String(encryptionConfig.ChaChaSigPublicKey));
        Array.Resize(ref buffer, (int)bufferLength);
        return(buffer);
    }
Beispiel #3
0
    public byte[] SignOpenMessage(byte[] singed)
    {
        long bufferSize = singed.Length - 64;

        byte[] buffer = new byte[bufferSize];

        NativeLibsodium.crypto_sign_open(buffer, ref bufferSize, singed, singed.Length, ChaChaSigPublicKey);
        return(buffer);
    }
        public byte[] SignOpenMessage(byte[] message)
        {
            long bufferLength = -1;

            NativeLibsodium.crypto_sign_open(buffer, ref bufferLength, message, message.Length, _publicKey);
            var result = new byte[bufferLength];

            Array.Copy(buffer, result, bufferLength);
            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Validates a signature with the public part of a KeyPair
        /// </summary>
        /// <returns>The validated byte array or an Exception.</returns>
        /// <param name="signed">Signed byte array.</param>
        /// <param name="publicKey">Public key to validate the signature with.</param>
        public static byte[] SignOpen(byte[] signed, byte[] publicKey)
        {
            byte[] opened  = new byte[signed.Length - CRYPTO_SIGN_BYTES];
            long   length  = signed.Length;
            int    success = NativeLibsodium.crypto_sign_open(opened, ref length, signed, signed.Length, publicKey);

            if (success != 0)
            {
                throw new Exception("Signature is invalid");
            }
            return(opened);
        }
Beispiel #6
0
        public static byte[] SignByteOpen(byte[] toValidate, byte[] publicSignKey)
        {
            if (toValidate.Length < CRYPTO_SIGN_BYTES)
            {
                // probably no keys left
                return(null);
            }

            byte[] checkedData      = new byte[toValidate.Length - CRYPTO_SIGN_BYTES];
            long   length           = checkedData.Length;
            long   toValidateLength = toValidate.Length;

            NativeLibsodium.crypto_sign_open(checkedData, ref length, toValidate, toValidateLength, publicSignKey);
            return(checkedData);
        }
Beispiel #7
0
        public byte[] SignOpenMessage(byte[] signed)
        {
            byte[] key    = Convert.FromBase64String(ChaChaSigPublicKey);
            byte[] buffer = new byte[signed.Length - 64];

            long bufferLength = 0;

            int ret = NativeLibsodium.crypto_sign_open(buffer, ref bufferLength, signed, signed.Length, key);

            if (ret == 0)
            {
                return(buffer);
            }
            return(null);
        }
    public byte[] SignOpenMessage(byte[] msg)
    {
        long bufLength = msg.Length - crypto_sign_BYTES;

        byte[] unsignedMsg = new byte[bufLength];

        int rc = NativeLibsodium.crypto_sign_open(unsignedMsg, ref bufLength, msg, msg.Length, _ChaChaSigPublicKey);

        if (rc != 0)
        {
            throw new Exception("Error encrypting message.");
        }

        return(unsignedMsg);
    }
    public byte[] SignOpenMessage(byte[] signed)
    {
        byte[] buffer       = new byte[2048];
        long   bufferLength = 2048;

        if (NativeLibsodium.crypto_sign_open(buffer, ref bufferLength, signed, signed.Length, ChaChaSigPublicKey) == 0)
        {
            Array.Resize(ref buffer, (int)bufferLength);
            return(buffer);
        }
        else
        {
            Debug.LogError("Incorrect Signature");
            return(null);
        }
    }
Beispiel #10
0
        public static void Test()
        {
            KeyPair signKeyPair = NewSingKeypair();

            byte[] toSign       = Encoding.UTF8.GetBytes("test!");
            byte[] signed       = new byte[toSign.Length + CRYPTO_SIGN_BYTES];
            long   length       = signed.Length;
            long   toSingLength = toSign.Length;

            NativeLibsodium.crypto_sign(signed, ref length, toSign, toSingLength, signKeyPair.secretKey);

            byte[] checkedData      = new byte[signed.Length - CRYPTO_SIGN_BYTES];
            long   clength          = checkedData.Length;
            long   toValidateLength = signed.Length;

            NativeLibsodium.crypto_sign_open(checkedData, ref clength, signed, toValidateLength, signKeyPair.publicKey);
        }
Beispiel #11
0
        /// <summary>
        /// Checks that some bytes were signed by some public key
        /// </summary>
        /// <returns>The byte open.</returns>
        /// <param name="toValidate">Bytes to validate.</param>
        /// <param name="publicSignKey">Public part of the sign key.</param>
        public static byte[] SignByteOpen(byte[] toValidate, byte[] publicSignKey)
        {
            if (toValidate.Length < CRYPTO_SIGN_BYTES)
            {
                throw new Exception($"{nameof(toValidate)} is shorter than the signature has to be.");
            }

            byte[] checkedData      = new byte[toValidate.Length - CRYPTO_SIGN_BYTES];
            long   length           = checkedData.Length;
            long   toValidateLength = toValidate.Length;
            int    success          = NativeLibsodium.crypto_sign_open(checkedData, ref length, toValidate, toValidateLength, publicSignKey);

            if (success == -1)
            {
                throw new Exception("The signed bytes are not valid");
            }
            return(checkedData);
        }
    public byte[] SignOpenMessage(byte[] signed)
    {
        if (NativeLibsodium.crypto_sign_keypair(Convert.FromBase64String(ChaChaSigPublicKey), Convert.FromBase64String(ChaChaSigPrivateKey)) != 0)
        {
            throw new Exception("Wrong Key pair");
        }

        byte[] buffer       = new byte[signed.LongLength - 64];
        long   bufferLength = buffer.LongLength;
        int    ret          = NativeLibsodium.crypto_sign_open(buffer, ref bufferLength, signed, signed.LongLength,
                                                               Convert.FromBase64String(ChaChaSigPublicKey));

        if (ret != 0)
        {
            throw new Exception("Error open signing message.");
        }

        return(buffer);
    }