Пример #1
0
        public static SharedSecret Import(
            ReadOnlySpan <byte> sharedSecret)
        {
            if (sharedSecret.Length > 128)
            {
                throw Error.Argument_SharedSecretLength(nameof(sharedSecret), 128.ToString());
            }

            Sodium.Initialize();

            SecureMemoryHandle sharedSecretHandle = null;
            bool success = false;

            try
            {
                SecureMemoryHandle.Import(sharedSecret, out sharedSecretHandle);
                success = true;
            }
            finally
            {
                if (!success && sharedSecretHandle != null)
                {
                    sharedSecretHandle.Dispose();
                }
            }

            return(new SharedSecret(sharedSecretHandle));
        }
Пример #2
0
        public static void GenerateBytes(
            Span <byte> bytes)
        {
            Sodium.Initialize();

            GenerateBytesCore(bytes);
        }
Пример #3
0
        public static void GenerateBytes(
            Span <byte> bytes)
        {
            if (bytes.Length == 0)
            {
                return;
            }

            Sodium.Initialize();

            GenerateBytesCore(bytes);
        }
Пример #4
0
        public static byte[] GenerateBytes(
            int count)
        {
            if (count < 0)
            {
                throw Error.ArgumentOutOfRange_GenerateNegativeCount(nameof(count));
            }

            Sodium.Initialize();

            byte[] bytes = new byte[count];
            GenerateBytesCore(bytes);
            return(bytes);
        }
Пример #5
0
 private protected Algorithm()
 {
     Sodium.Initialize();
 }
Пример #6
0
 private protected RandomGenerator()
 {
     Sodium.Initialize();
 }
Пример #7
0
 internal Algorithm()
 {
     Sodium.Initialize();
 }