Пример #1
0
        public async Task EncryptFPE_FFS_BIRTH_DATE_InValidPassthroughCharacters_Fail()
        {
            var credentials = UbiqFactory.ReadCredentialsFromFile("..\\..\\credentials", "default");

            byte[] tweakFF1 = new byte[0];

            var ffsName  = "BIRTH_DATE";
            var original = "01/01/2020";

            using (var ubiqEncryptDecrypt = new UbiqFPEEncryptDecrypt(credentials))
            {
                var ex = await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(async() => await ubiqEncryptDecrypt.EncryptAsync(ffsName, original, tweakFF1));

                Assert.IsTrue(ex.Message.Contains("invalid character found in the input"));
            }
        }
Пример #2
0
        public async Task EncryptFPE_FFS_ALPHANUM_SSN_ValidPassthroughCharacters_Success()
        {
            var credentials = UbiqFactory.ReadCredentialsFromFile("..\\..\\credentials", "default");

            byte[] tweakFF1 = new byte[0];

            var ffsName  = "ALPHANUM_SSN";
            var original = " 01&23-456-78-90";

            using (var ubiqEncryptDecrypt = new UbiqFPEEncryptDecrypt(credentials))
            {
                var cipher = await ubiqEncryptDecrypt.EncryptAsync(ffsName, original, tweakFF1);

                var decrypted = await ubiqEncryptDecrypt.DecryptAsync(ffsName, cipher, tweakFF1);

                Assert.AreEqual(original, decrypted);
            }
        }
Пример #3
0
        public async Task EncryptFPE_FFS_BIRTH_DATE_Success()
        {
            // TODO: Figure out how to handle credentials
            var credentials = UbiqFactory.ReadCredentialsFromFile("..\\..\\credentials", "default");

            byte[] tweakFF1 = new byte[0];

            var ffsName  = "BIRTH_DATE";
            var original = "01-01-2020";

            using (var ubiqEncryptDecrypt = new UbiqFPEEncryptDecrypt(credentials))
            {
                var cipher = await ubiqEncryptDecrypt.EncryptAsync(ffsName, original, tweakFF1);

                var decrypted = await ubiqEncryptDecrypt.DecryptAsync(ffsName, cipher, tweakFF1);

                Assert.AreEqual(original, decrypted);
            }
        }
Пример #4
0
        public async Task EncryptFPE_XPlatformValidation_Success()
        {
            var credentials = UbiqFactory.ReadCredentialsFromFile("..\\..\\credentials", "default");

            byte[] tweakFF1 = new byte[0];

            var ffsName  = "ALPHANUM_SSN";
            var original = "123 456 789";

            using (var ubiqEncryptDecrypt = new UbiqFPEEncryptDecrypt(credentials))
            {
                var cipher = await ubiqEncryptDecrypt.EncryptAsync(ffsName, original, tweakFF1);

                Debug.WriteLine($"encrypted: {cipher}");
                var decrypted = await ubiqEncryptDecrypt.DecryptAsync(ffsName, cipher, tweakFF1);

                Debug.WriteLine($"decrypted: {decrypted}");
                Assert.AreEqual(original, decrypted);
            }
        }
Пример #5
0
        public async Task EncryptFPE_FFS_GENERIC_STRING_Success()
        {
            var credentials = UbiqFactory.ReadCredentialsFromFile("..\\..\\credentials", "default");

            byte[] tweakFF1 =
            {
                (byte)0x39, (byte)0x38, (byte)0x37, (byte)0x36,
                (byte)0x35, (byte)0x34, (byte)0x33, (byte)0x32,
                (byte)0x31, (byte)0x30, (byte)0x33, (byte)0x32,
                (byte)0x31, (byte)0x30, (byte)0x32,
            };

            var ffsName  = "GENERIC_STRING";
            var original = "A STRING OF AT LEAST 15 UPPER CHARACTERS";

            using (var ubiqEncryptDecrypt = new UbiqFPEEncryptDecrypt(credentials))
            {
                var cipher = await ubiqEncryptDecrypt.EncryptAsync(ffsName, original, tweakFF1);

                var decrypted = await ubiqEncryptDecrypt.DecryptAsync(ffsName, cipher, tweakFF1);

                Assert.AreEqual(original, decrypted);
            }
        }
Пример #6
0
        private static void RunCommand(CommandLineOptions options)
        {
            if (options.Simple == options.Piecewise)
            {
                throw new InvalidOperationException("simple or piecewise API option need to be specified but not both");
            }

            if (options.Encrypt == options.Decrypt)
            {
                throw new InvalidOperationException("Encryption or Decrytion have to be specified but not both");
            }

            if (!File.Exists(options.InputFile))
            {
                throw new InvalidOperationException($"Input file does not exist: {options.InputFile}");
            }

            IUbiqCredentials ubiqCredentials;

            if (options.Credentials == null)
            {
                try
                {
                    // no file specified, so fall back to ENV vars and default host, if any
                    ubiqCredentials = UbiqFactory.CreateCredentials(
                        accessKeyId: null,
                        secretSigningKey: null,
                        secretCryptoAccessKey: null,
                        host: null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Exception caught while setting credentials:  {ex.Message}");
                    Console.WriteLine($"Required environment variables not set'");
                    return;
                }
            }
            else
            {
                try
                {
                    // read credentials from caller-specified section of specified config file
                    ubiqCredentials = UbiqFactory.ReadCredentialsFromFile(options.Credentials, options.Profile);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Exception caught while reading credentials:  {ex.Message}");
                    Console.WriteLine($"Check pathname of credentials file '{options.Credentials}' and chosen profile '{options.Profile}'");
                    return;
                }
            }

            // check input file size - we already know it exists
            {
                long maxSimpleSize = 50 * 0x100000;                     // 50MB
                var  inputFileInfo = new FileInfo(options.InputFile);
                if (options.Simple && (inputFileInfo.Length > maxSimpleSize))
                {
                    Console.WriteLine("NOTE: This is only for demonstration purposes and is designed to work on memory");
                    Console.WriteLine("      constrained devices.  Therefore, this sample application will switch to");
                    Console.WriteLine("      the piecewise APIs for files larger than {0} bytes in order to reduce", maxSimpleSize);
                    Console.WriteLine("      excessive resource usages on resource constrained IoT devices");
                    options.Simple    = false;
                    options.Piecewise = true;
                }
            }

            if (options.Simple)
            {
                if (options.Encrypt)
                {
                    SimpleEncryptionAsync(options.InputFile, options.OutputFile, ubiqCredentials).Wait();
                }
                else
                {
                    SimpleDecryptionAsync(options.InputFile, options.OutputFile, ubiqCredentials).Wait();
                }
            }
            else
            {
                if (options.Encrypt)
                {
                    PiecewiseEncryptionAsync(options.InputFile, options.OutputFile, ubiqCredentials).Wait();
                }
                else
                {
                    PiecewiseDecryptionAsync(options.InputFile, options.OutputFile, ubiqCredentials).Wait();
                }
            }
        }
Пример #7
0
        private static void RunCommand(CommandLineOptions options)
        {
            try
            {
                if (options.Simple == options.Bulk)
                {
                    throw new InvalidOperationException("simple or bulk API option need to be specified but not both");
                }

                if (string.IsNullOrEmpty(options.EncryptText) && string.IsNullOrEmpty(options.DecryptText))
                {
                    throw new InvalidOperationException("Encryption or Decryption must be specified");
                }

                if (!string.IsNullOrEmpty(options.EncryptText) && !string.IsNullOrEmpty(options.DecryptText))
                {
                    throw new InvalidOperationException("Encryption text or Decrytion text have to be specified but not both");
                }

                if (string.IsNullOrEmpty(options.FfsName))
                {
                    throw new InvalidOperationException("ffsname must be specified");
                }

                IUbiqCredentials ubiqCredentials;
                if (options.Credentials == null)
                {
                    try
                    {
                        // no file specified, so fall back to ENV vars and default host, if any
                        ubiqCredentials = UbiqFactory.CreateCredentials(
                            accessKeyId: null,
                            secretSigningKey: null,
                            secretCryptoAccessKey: null,
                            host: null);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Exception caught while setting credentials:  {ex.Message}");
                        Console.WriteLine($"Required environment variables not set");
                        return;
                    }
                }
                else
                {
                    try
                    {
                        // read credentials from caller-specified section of specified config file
                        ubiqCredentials = UbiqFactory.ReadCredentialsFromFile(options.Credentials, options.Profile);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Exception caught while reading credentials:  {ex.Message}");
                        Console.WriteLine($"Check pathname of credentials file '{options.Credentials}' and chosen profile '{options.Profile}'");
                        return;
                    }
                }

                if (options.Simple)
                {
                    if (!string.IsNullOrEmpty(options.EncryptText))
                    {
                        SimpleEncryptionAsync(options, ubiqCredentials).GetAwaiter().GetResult();
                    }
                    else
                    {
                        SimpleDecryptionAsync(options, ubiqCredentials).GetAwaiter().GetResult();
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(options.EncryptText))
                    {
                        BulkEncryptionAsync(options, ubiqCredentials).GetAwaiter().GetResult();
                    }
                    else
                    {
                        BulkDecryptionAsync(options, ubiqCredentials).GetAwaiter().GetResult();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception: {e.Message}");
                Console.WriteLine(e.StackTrace);
                Environment.Exit(1);
            }
        }