예제 #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
파일: Algorithm.cs 프로젝트: unfug/nsec
 private protected Algorithm()
 {
     Sodium.Initialize();
 }
예제 #6
0
 private protected RandomGenerator()
 {
     Sodium.Initialize();
 }
예제 #7
0
 internal Algorithm()
 {
     Sodium.Initialize();
 }