574. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/26/2017 10:44:23 PM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

574.1 Files compared

# Location File Last Modified
1 Fri Oct 27 02:44:23 2017 UTC
2 OSCIF_BMS_v2_iter 2_September_2017.zip\BMS_Cand\Source\Sources\BMS.Vista.TestEis\BMS.Utils CustomEncryption.cs Wed Oct 18 18:47:02 2017 UTC

574.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 0 0
Changed 0 0
Inserted 1 151
Removed 0 0

574.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

574.4 Active regular expressions

No regular expressions were active.

574.5 Comparison detail

        1   using Syst em;
        2   using Syst em.Securit y.Cryptogr aphy;
        3   using Syst em.Text;
        4   using Syst em.IO;
        5   using Syst em.Collect ions.Gener ic;
        6  
        7   namespace  BMS.Utils
        8   {
        9       class  Encryptors
        10       {
        11           pu blic ICryp toTransfor m Encrypto r { get; s et; }
        12           pu blic ICryp toTransfor m Decrypto r { get; s et; }
        13       }
        14  
        15       public  class Cus tomEncrypt ion
        16       {
        17           co nst string  str = "Lg BTAHUAcABl AHIALgBTAG UAYwByAGUA dAAuAFAAQA BhAHMAcwB3 AG8AcgBkAC 4A";
        18           st atic Dicti onary<stri ng, Encryp tors> salt Encryptors  = new Dic tionary<st ring, Encr yptors>();
        19  
        20           // / <summary >
        21           // / Encrypti on method.
        22           // / </summar y>
        23           // / <param n ame="input ">string t o encrypt< /param>
        24           // / <param n ame="salt" >salt used  for encry ption</par am>
        25           // / <returns >encrypted  string</r eturns>
        26           pu blic stati c string E ncrypt(str ing input,  string sa lt)
        27           {
        28                DateTime  entryInLo gMethodTim e = DateTi me.UtcNow;
        29                if (Info World.Trac ing.IWTrac e.IsEntryE nabled)
        30                {
        31                    Info World.Trac ing.IWTrac e.Entry(Sy stem.Refle ction.Meth odBase.Get CurrentMet hod(), ent ryInLogMet hodTime);
        32                }
        33                try
        34                {                
        35                    if ( !saltEncry ptors.Cont ainsKey(sa lt))
        36                    {
        37                         // symmetr ic encrypt ion algori thm
        38                         using (Aes Managed ae s = new Ae sManaged() )
        39                         {                          
        40                             byte[]  saltBytes  = UTF8Enc oding.UTF8 .GetBytes( salt);
        41                             // We' re using t he PBKDF2  standard f or passwor d-based ke y generati on
        42                             using  (Rfc2898De riveBytes  rfc = new  Rfc2898Der iveBytes(U TF8Encodin g.Unicode. GetString( Convert.Fr omBase64St ring(str)) , saltByte s))
        43                             {
        44                                 ae s.Key = rf c.GetBytes (aes.KeySi ze / 8);
        45                                 ae s.IV = rfc .GetBytes( aes.BlockS ize / 8);
        46                             }
        47                             saltEn cryptors.A dd(salt, n ew Encrypt ors() { En cryptor =  aes.Create Encryptor( ), Decrypt or = aes.C reateDecry ptor() });
        48                         }
        49                    }
        50                    
        51                    usin g (MemoryS tream encr yptStream  = new Memo ryStream() )
        52                    {
        53                         byte[] utf data = UTF 8Encoding. UTF8.GetBy tes(input) ;
        54                         CryptoStre am encrypt or = new C ryptoStrea m(encryptS tream, sal tEncryptor s[salt].En cryptor, C ryptoStrea mMode.Writ e);
        55  
        56                         encryptor. Write(utfd ata, 0, ut fdata.Leng th);
        57                         encryptor. Flush();
        58                         encryptor. FlushFinal Block();
        59  
        60                         return Enc ryptor.Con vertToAlph abetString (encryptSt ream.ToArr ay());
        61                    }                  
        62                }
        63                finally
        64                {
        65                    if ( InfoWorld. Tracing.IW Trace.IsEx itEnabled)
        66                    {
        67                         InfoWorld. Tracing.IW Trace.Exit (System.Re flection.M ethodBase. GetCurrent Method(),  DateTime.U tcNow, ent ryInLogMet hodTime);
        68                    }
        69                }
        70           }
        71  
        72           // / <summary >
        73           // / Decrypti on method.
        74           // / </summar y>
        75           // / <param n ame="input ">String t o decrypt. </param>
        76           // / <param n ame="salt" >salt used  for decry ption</par am>
        77           // / <returns >Decrypted  string.</ returns>
        78           pu blic stati c string D ecrypt(str ing input,  string sa lt)
        79           {
        80                DateTime  entryInLo gMethodTim e = DateTi me.UtcNow;
        81                if (Info World.Trac ing.IWTrac e.IsEntryE nabled)
        82                {
        83                    Info World.Trac ing.IWTrac e.Entry(Sy stem.Refle ction.Meth odBase.Get CurrentMet hod(), ent ryInLogMet hodTime);
        84                }
        85                try
        86                {
        87                    if ( !saltEncry ptors.Cont ainsKey(sa lt))
        88                    {
        89                         // symmetr ic encrypt ion algori thm
        90                         using (Aes Managed ae s = new Ae sManaged() )
        91                         {                          
        92                             byte[]  saltBytes  = UTF8Enc oding.UTF8 .GetBytes( salt);
        93                             // We' re using t he PBKDF2  standard f or passwor d-based ke y generati on
        94                             using  (Rfc2898De riveBytes  rfc = new  Rfc2898Der iveBytes(U TF8Encodin g.Unicode. GetString( Convert.Fr omBase64St ring(str)) , saltByte s))
        95                             {
        96                                 ae s.Key = rf c.GetBytes (aes.KeySi ze / 8);
        97                                 ae s.IV = rfc .GetBytes( aes.BlockS ize / 8);
        98                             }
        99                             saltEn cryptors.A dd(salt, n ew Encrypt ors() { En cryptor =  aes.Create Encryptor( ), Decrypt or = aes.C reateDecry ptor() });
        100                         }
        101                    }
        102  
        103                    // O utput stre am, can be  also a Fi leStream
        104                    usin g (MemoryS tream decr yptStream  = new Memo ryStream() )
        105                    {
        106                         byte[] enc ryptBytes  = Encrypto r.ConvertF romAlphabe tString(in put);
        107                         CryptoStre am decrypt or = new C ryptoStrea m(decryptS tream, sal tEncryptor s[salt].De cryptor, C ryptoStrea mMode.Writ e);
        108  
        109                         decryptor. Write(encr yptBytes,  0, encrypt Bytes.Leng th);
        110                         decryptor. Flush();
        111                         decryptor. FlushFinal Block();
        112  
        113                         // Showing  our decry pted conte nt
        114                         byte[] dec ryptBytes  = decryptS tream.ToAr ray();
        115                         return UTF 8Encoding. UTF8.GetSt ring(decry ptBytes, 0 , decryptB ytes.Lengt h);                          
        116                    }                  
        117                }
        118                catch (E xception e x)
        119                {
        120                    thro w new Exce ption("Str ing to dec rypt is in correct!",  ex);
        121                }
        122                finally
        123                {
        124                    if ( InfoWorld. Tracing.IW Trace.IsEx itEnabled)
        125                    {
        126                         InfoWorld. Tracing.IW Trace.Exit (System.Re flection.M ethodBase. GetCurrent Method(),  DateTime.U tcNow, ent ryInLogMet hodTime);
        127                    }
        128                }
        129           }
        130  
        131           pu blic stati c string G etRandomSa lt(string  userName)
        132           {
        133                DateTime  entryInLo gMethodTim e = DateTi me.UtcNow;
        134                if (Info World.Trac ing.IWTrac e.IsEntryE nabled)
        135                {
        136                    Info World.Trac ing.IWTrac e.Entry(Sy stem.Refle ction.Meth odBase.Get CurrentMet hod(), ent ryInLogMet hodTime);
        137                }
        138                try
        139                {
        140                    retu rn Convert .ToBase64S tring(ASCI IEncoding. ASCII.GetB ytes(userN ame));
        141                }
        142                finally
        143                {
        144                    if ( InfoWorld. Tracing.IW Trace.IsEx itEnabled)
        145                    {
        146                         InfoWorld. Tracing.IW Trace.Exit (System.Re flection.M ethodBase. GetCurrent Method(),  DateTime.U tcNow, ent ryInLogMet hodTime);
        147                    }
        148                }
        149           }
        150       }
        151   }