Beispiel #1
0
        /// <summary>
        /// Encrypts supplied buffer using xsalsa20_poly1305 algorithm, using supplied key and nonce to perform encryption.
        /// </summary>
        /// <param name="source">Contents to encrypt.</param>
        /// <param name="target">Buffer to encrypt to.</param>
        /// <param name="key">Key to use for encryption.</param>
        /// <param name="nonce">Nonce to use for encryption.</param>
        /// <returns>Encryption status.</returns>
        // Token: 0x0600014C RID: 332 RVA: 0x00004510 File Offset: 0x00002710
        public unsafe static int Encrypt(ReadOnlySpan <byte> source, Span <byte> target, ReadOnlySpan <byte> key, ReadOnlySpan <byte> nonce)
        {
            int result;

            fixed(byte *pinnableReference = source.GetPinnableReference())
            {
                byte *message = pinnableReference;

                fixed(byte *pinnableReference2 = target.GetPinnableReference())
                {
                    byte *buffer = pinnableReference2;

                    fixed(byte *pinnableReference3 = key.GetPinnableReference())
                    {
                        byte *key2 = pinnableReference3;

                        fixed(byte *pinnableReference4 = nonce.GetPinnableReference())
                        {
                            byte *nonce2 = pinnableReference4;

                            result = Interop._SodiumSecretBoxCreate(buffer, message, (ulong)((long)source.Length), nonce2, key2);
                        }
                    }
                }
            }

            return(result);
        }