示例#1
0
 public KeyPair()
 {
     skBytes = new byte[SKEY_LEN];
     vkBytes = new byte[VKEY_LEN];
     NativeLibsodium.crypto_sign_keypair(vkBytes, skBytes);
     Debug.Log($"sk: {Helper.ByteArrayToHexString(skBytes)}, vk: {Helper.ByteArrayToHexString(vkBytes)} ");
     vkString = Helper.ByteArrayToHexString(vkBytes).ToLower();
 }
示例#2
0
文件: Encrypt.cs 项目: Coflnet/cloud
        public static KeyPair NewSingKeypair()
        {
            KeyPair pair = new KeyPair();

            pair.publicKey = new byte[CRYPTO_SIGN_PUBLICKEYBYTES];
            pair.secretKey = new byte[CRYPTO_SIGN_SECRETKEYBYTES];
            NativeLibsodium.crypto_sign_keypair(pair.publicKey, pair.secretKey);
            return(pair);
        }
示例#3
0
        /// <inheritdoc/>
        public override SigningKeyPair GenerateKeyPair()
        {
            SigningKeyPair keyPair = new SigningKeyPair(new byte[32],new byte[64]);


            if(NativeLibsodium.crypto_sign_keypair(keyPair.publicKey,keyPair.secretKey) != 0)
                throw new Exception("Could not create new KeyPair");

            keyPair.algorythm = this;
            return keyPair;
        }
    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);
    }