internal FpeEncryptedKeyCacheManager(IUbiqCredentials credentials, UbiqWebServices ubiqWebServices)
 {
     _cacheLock       = false;
     _credentials     = credentials;
     _ubiqWebServices = ubiqWebServices;
     _cache           = new MemoryCache("fpeCache");
     InitCache();
 }
Exemplo n.º 2
0
        private static async Task SimpleDecryptionAsync(CommandLineOptions options, IUbiqCredentials ubiqCredentials)
        {
            // default tweak in case the FFS model allows for external tweak insertion
            byte[] tweakFF1 = {};

            var plainText = await UbiqFPEEncryptDecrypt.DecryptAsync(ubiqCredentials, options.DecryptText, options.FfsName, tweakFF1);

            Console.WriteLine($"DECRYPTED plainText= {plainText}\n");
            return;
        }
Exemplo n.º 3
0
        public static async Task <string> EncryptAsync(IUbiqCredentials ubiqCredentials, string inputText, string ffsName, byte[] tweak)
        {
            var response = string.Empty;

            using (var ubiqEncrypt = new UbiqFPEEncryptDecrypt(ubiqCredentials))
            {
                response = await ubiqEncrypt.EncryptAsync(ffsName, inputText, tweak);
            }

            return(response);
        }
Exemplo n.º 4
0
        private const int _ff1_base2_min_length = 20;         // NIST requirement ceil(log(2(1000000)))

        #endregion

        #region Constructors

        public UbiqFPEEncryptDecrypt(IUbiqCredentials ubiqCredentials)
        {
            _isInited        = false;
            _ubiqCredentials = ubiqCredentials;
            _ubiqWebServices = new UbiqWebServices(_ubiqCredentials);
            _ffsCache        = new FfsCacheManager(_ubiqCredentials, _ubiqWebServices);
            _fpeCache        = new FpeEncryptedKeyCacheManager(_ubiqCredentials, _ubiqWebServices);
            _fpeTransactions = new FpeTransactionManager(new UbiqWebServices(_ubiqCredentials));
            _fpeProcessor    = new FpeProcessor(_fpeTransactions, 1);
            _fpeProcessor.StartUp();
        }
Exemplo n.º 5
0
        private static async Task BulkDecryptionAsync(CommandLineOptions options, IUbiqCredentials ubiqCredentials)
        {
            // default tweak in case the FFS model allows for external tweak insertion
            byte[] tweakFF1 = {};

            using (var ubiqEncryptDecrypt = new UbiqFPEEncryptDecrypt(ubiqCredentials))
            {
                var plainText = await ubiqEncryptDecrypt.DecryptAsync(options.FfsName, options.DecryptText, tweakFF1);

                Console.WriteLine($"DECRYPTED plainText= {plainText}\n");
            }

            return;
        }
Exemplo n.º 6
0
        internal UbiqWebServices(IUbiqCredentials ubiqCredentials)
        {
            _ubiqCredentials = ubiqCredentials;

            if (!_ubiqCredentials.Host.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            {
                _baseUrl = $"https://{_ubiqCredentials.Host}";
            }
            else
            {
                _baseUrl = _ubiqCredentials.Host;
            }

            // thread-safe lazy init: 'BuildHttpClient' doesn't get called
            // until _lazyHttpClient.Value is accessed
            _lazyHttpClient = new Lazy <HttpClient>(BuildHttpClient);
        }
Exemplo n.º 7
0
        public static async Task <byte[]> DecryptAsync(IUbiqCredentials ubiqCredentials, byte[] data)
        {
            // handy inline function
            void WriteBytesToStream(Stream stream, byte[] bytes)
            {
                stream.Write(bytes, 0, bytes.Length);
            }

            using (var memoryStream = new MemoryStream())
            {
                using (var ubiqDecrypt = new UbiqDecrypt(ubiqCredentials))
                {
                    WriteBytesToStream(memoryStream, ubiqDecrypt.Begin());
                    WriteBytesToStream(memoryStream, await ubiqDecrypt.UpdateAsync(data, 0, data.Length).ConfigureAwait(false));
                    WriteBytesToStream(memoryStream, ubiqDecrypt.End());
                }

                return(memoryStream.ToArray());
            }
        }
Exemplo n.º 8
0
 internal static string GenerateAccessKeyUrl(IUbiqCredentials credentials)
 {
     return(WebUtility.UrlEncode(credentials.AccessKeyId));
 }
Exemplo n.º 9
0
 internal static string GenerateFpeUrl(string ffsName, int?keyNumber, IUbiqCredentials credentials)
 {
     return($"papi={WebUtility.UrlEncode(credentials.AccessKeyId)}&ffs_name={WebUtility.UrlEncode(ffsName)}&keyNumber={(keyNumber.HasValue ? keyNumber.Value.ToString() : string.Empty)}");
 }
Exemplo n.º 10
0
 internal static string GenerateFfsUrl(string ffsName, IUbiqCredentials credentials)
 {
     return($"papi={WebUtility.UrlEncode(credentials.AccessKeyId)}&ffs_name={WebUtility.UrlEncode(ffsName)}");
 }
Exemplo n.º 11
0
        private static async Task PiecewiseDecryptionAsync(string inFile, string outFile, IUbiqCredentials ubiqCredentials)
        {
            using (var cipherStream = new FileStream(inFile, FileMode.Open))
            {
                using (var plainStream = new FileStream(outFile, FileMode.Create))
                {
                    using (var ubiqDecrypt = new UbiqDecrypt(ubiqCredentials))
                    {
                        var plainBytes = ubiqDecrypt.Begin();
                        plainStream.Write(plainBytes, 0, plainBytes.Length);

                        var cipherBytes = new byte[0x20000];
                        int bytesRead   = 0;
                        while ((bytesRead = cipherStream.Read(cipherBytes, 0, cipherBytes.Length)) > 0)
                        {
                            plainBytes = await ubiqDecrypt.UpdateAsync(cipherBytes, 0, bytesRead);

                            plainStream.Write(plainBytes, 0, plainBytes.Length);
                        }

                        plainBytes = ubiqDecrypt.End();
                        plainStream.Write(plainBytes, 0, plainBytes.Length);
                    }
                }
            }
        }
Exemplo n.º 12
0
        private static async Task SimpleDecryptionAsync(string inFile, string outFile, IUbiqCredentials ubiqCredentials)
        {
            var cipherBytes = File.ReadAllBytes(inFile);
            var plainBytes  = await UbiqDecrypt.DecryptAsync(ubiqCredentials, cipherBytes);

            File.WriteAllBytes(outFile, plainBytes);
        }
Exemplo n.º 13
0
 public UbiqDecrypt(IUbiqCredentials ubiqCredentials)
 {
     _ubiqWebServices = new UbiqWebServices(ubiqCredentials);
 }
Exemplo n.º 14
0
 public UbiqEncrypt(IUbiqCredentials ubiqCredentials, int usesRequested)
 {
     _ubiqCredentials = ubiqCredentials;
     _usesRequested   = usesRequested;
     _ubiqWebServices = new UbiqWebServices(_ubiqCredentials);
 }