Пример #1
0
        public static byte[] GetSalt(byte[] data)
        {
            byte[] salt = new byte[SaltLength];

            if (!ToxEncryptionFunctions.GetSalt(data, salt))
                return null;

            return salt;
        }
Пример #2
0
        public static byte[] GetSalt(byte[] data)
        {
            byte[] salt = new byte[SaltLength];

            if (!ToxEncryptionFunctions.GetSalt(data, salt))
            {
                return(null);
            }

            return(salt);
        }
Пример #3
0
        public static byte[] GetSalt(byte[] data)
        {
            byte[] salt = new byte[ToxEncryptionFunctions.PassSaltLength()];

            if (ToxEncryptionFunctions.GetSalt(data, salt) == -1)
            {
                return(null);
            }

            return(salt);
        }
Пример #4
0
        internal static ToxPassKey? DeriveKey(string passphrase)
        {
            byte[] pp = Encoding.UTF8.GetBytes(passphrase);
            var error = ToxErrorKeyDerivation.Ok;
            var key = new ToxPassKey();

            if (!ToxEncryptionFunctions.DeriveKeyFromPass(pp, (uint)pp.Length, ref key, ref error) || error != ToxErrorKeyDerivation.Ok)
                return null;

            return key;
        }
Пример #5
0
        public static byte[] EncryptData(byte[] data, string passphrase)
        {
            byte[] output = new byte[data.Length + ToxEncryptionFunctions.PassEncryptionExtraLength()];
            byte[] pp     = Encoding.UTF8.GetBytes(passphrase);

            if (ToxEncryptionFunctions.PassEncrypt(data, (uint)data.Length, pp, (uint)pp.Length, output) == -1)
            {
                return(null);
            }

            return(output);
        }
Пример #6
0
        public static byte[] DeriveKey(string passphrase)
        {
            byte[] pp  = Encoding.UTF8.GetBytes(passphrase);
            byte[] key = new byte[ToxEncryptionFunctions.PassKeyLength()];

            if (ToxEncryptionFunctions.DeriveKeyFromPass(pp, (uint)pp.Length, key) == -1)
            {
                return(null);
            }

            return(key);
        }
Пример #7
0
        internal static ToxPassKey? DeriveKey(string passphrase, byte[] salt)
        {
            if (salt.Length < SaltLength)
                return null;

            byte[] pp = Encoding.UTF8.GetBytes(passphrase);
            var error = ToxErrorKeyDerivation.Ok;
            var key = new ToxPassKey();

            if (!ToxEncryptionFunctions.DeriveKeyWithSalt(pp, (uint)pp.Length, salt, ref key, ref error) || error != ToxErrorKeyDerivation.Ok)
                return null;

            return key;
        }
Пример #8
0
        public static byte[] GetSalt(byte[] data, out ToxErrorGetSalt error)
        {
            byte[] salt = new byte[ToxEncryptionConstants.SaltLength];

            error = ToxErrorGetSalt.Ok;
            var success = ToxEncryptionFunctions.GetSalt(data, salt, ref error);

            if (success && error == ToxErrorGetSalt.Ok)
            {
                return(salt);
            }

            return(null);
        }
Пример #9
0
        public static byte[] DeriveKey(string passphrase, byte[] salt)
        {
            if (salt.Length < ToxEncryptionFunctions.PassSaltLength())
            {
                return(null);
            }

            byte[] pp  = Encoding.UTF8.GetBytes(passphrase);
            byte[] key = new byte[ToxEncryptionFunctions.PassKeyLength()];

            if (ToxEncryptionFunctions.DeriveKeyWithSalt(pp, (uint)pp.Length, salt, key) == -1)
            {
                return(null);
            }

            return(key);
        }
Пример #10
0
        public static byte[] DecryptData(byte[] data, ToxEncryptionKey key, out ToxErrorDecryption error)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            if (key == null)
                throw new ArgumentNullException("key");

            byte[] output = new byte[data.Length - EncryptionExtraLength];
            var pass = key.ToPassKey();
            error = ToxErrorDecryption.Ok;

            if (!ToxEncryptionFunctions.PassKeyDecrypt(data, (uint)data.Length, ref pass, output, ref error) || error != ToxErrorDecryption.Ok)
                return null;

            return output;
        }
Пример #11
0
        public static byte[] DecryptData(byte[] data, string passphrase)
        {
            byte[] output = new byte[data.Length + ToxEncryptionFunctions.PassEncryptionExtraLength()];
            byte[] pp     = Encoding.UTF8.GetBytes(passphrase);
            byte[] result;

            int length = ToxEncryptionFunctions.PassDecrypt(data, (uint)data.Length, pp, (uint)pp.Length, output);

            if (length == -1)
            {
                return(null);
            }

            result = new byte[length];
            Array.Copy(output, 0, result, 0, length);

            return(result);
        }
Пример #12
0
        public static byte[] EncryptData(byte[] data, string password, out ToxErrorEncryption error)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (password == null)
            {
                throw new ArgumentNullException("password");
            }

            byte[] output    = new byte[data.Length + EncryptionExtraLength];
            byte[] passBytes = Encoding.UTF8.GetBytes(password);
            error = ToxErrorEncryption.Ok;

            if (!ToxEncryptionFunctions.PassEncrypt(data, (uint)data.Length, passBytes, (uint)passBytes.Length, output, ref error) || error != ToxErrorEncryption.Ok)
            {
                return(null);
            }

            return(output);
        }
Пример #13
0
        public static byte[] EncryptData(byte[] data, ToxEncryptionKey key, out ToxErrorEncryption error)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            byte[] output = new byte[data.Length + EncryptionExtraLength];
            var    pass   = key.ToPassKey();

            error = ToxErrorEncryption.Ok;

            if (!ToxEncryptionFunctions.PassKeyEncrypt(data, (uint)data.Length, ref pass, output, ref error) || error != ToxErrorEncryption.Ok)
            {
                return(null);
            }

            return(output);
        }
Пример #14
0
 public static bool IsDataEncrypted(byte[] data)
 {
     return(ToxEncryptionFunctions.IsDataEncrypted(data));
 }
Пример #15
0
 public static bool IsDataEncrypted(byte[] data) => ToxEncryptionFunctions.IsDataEncrypted(data);