576. 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.

576.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 Encryptor.cs Wed Oct 18 18:47:02 2017 UTC

576.2 Comparison summary

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

576.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

576.4 Active regular expressions

No regular expressions were active.

576.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  
        6   namespace  BMS.Utils
        7   {
        8       /// <s ummary>
        9       /// En cryption/d ecryption  utility cl ass.
        10       /// </ summary>
        11       public  class Enc ryptor
        12       {
        13           // const stri ng encrypt ion_passwo rd = ".the P@assword. ";
        14           co nst string  encryptio n_saltByte s = ".salt IsGoodForY ou.";
        15  
        16           // / <summary >
        17           // / Encrypti on method.
        18           // / </summar y>
        19           // / <param n ame="input ">string t o encrypt< /param>
        20           // / <returns >encrypted  string</r eturns>
        21           pu blic stati c string E ncrypt(str ing input,  string en cryptionPa ssword)
        22           {
        23                DateTime  entryInLo gMethodTim e = DateTi me.UtcNow;
        24                if (Info World.Trac ing.IWTrac e.IsEntryE nabled)
        25                {
        26                    Info World.Trac ing.IWTrac e.Entry(Sy stem.Refle ction.Meth odBase.Get CurrentMet hod(), ent ryInLogMet hodTime);
        27                }
        28                try
        29                {
        30                    stri ng data =  input;
        31                    byte [] utfdata  = UTF8Enc oding.UTF8 .GetBytes( data);
        32                    byte [] saltByt es = UTF8E ncoding.UT F8.GetByte s(encrypti on_saltByt es);
        33  
        34                    // s ymmetric e ncryption  algorithm
        35                    usin g (AesMana ged aes =  new AesMan aged())
        36                    {
        37                         // Setting  parameter s
        38                         aes.BlockS ize = aes. LegalBlock Sizes[0].M axSize;
        39                         aes.KeySiz e = aes.Le galKeySize s[0].MaxSi ze;
        40  
        41                         // We're u sing the P BKDF2 stan dard for p assword-ba sed key ge neration
        42                         using (Rfc 2898Derive Bytes rfc  = new Rfc2 898DeriveB ytes(encry ptionPassw ord, saltB ytes))
        43                         {
        44                             aes.Ke y = rfc.Ge tBytes(aes .KeySize /  8);
        45                             aes.IV  = rfc.Get Bytes(aes. BlockSize  / 8);
        46                         }
        47  
        48                         // Encrypt ion
        49                         ICryptoTra nsform enc ryptTransf  = aes.Cre ateEncrypt or();
        50  
        51                         using (Mem oryStream  encryptStr eam = new  MemoryStre am())
        52                         {
        53                             Crypto Stream enc ryptor = n ew CryptoS tream(encr yptStream,  encryptTr ansf, Cryp toStreamMo de.Write);
        54  
        55                             encryp tor.Write( utfdata, 0 , utfdata. Length);
        56                             encryp tor.Flush( );
        57                             encryp tor.FlushF inalBlock( ); //       encryptor .Close();
        58  
        59                             byte[]  encryptBy tes = encr yptStream. ToArray();
        60                             //stri ng encrypt edString =  Encoding. BigEndianU nicode.Get String(enc ryptBytes,  0, encryp tBytes.Len gth);             
        61                             string  encrypted String = C onvertToAl phabetStri ng(encrypt Bytes);
        62  
        63                             return  encrypted String;
        64                         }
        65                    }
        66                }
        67                finally
        68                {
        69                    if ( InfoWorld. Tracing.IW Trace.IsEx itEnabled)
        70                    {
        71                         InfoWorld. Tracing.IW Trace.Exit (System.Re flection.M ethodBase. GetCurrent Method(),  DateTime.U tcNow, ent ryInLogMet hodTime);
        72                    }
        73                }
        74           }
        75  
        76           // / <summary >
        77           // / Decrypti on method.
        78           // / </summar y>
        79           // / <param n ame="input ">String t o decrypt. </param>
        80           // / <returns >Decrypted  string.</ returns>
        81           pu blic stati c string D ecrypt(str ing input,  string en cryptionPa ssword)
        82           {
        83                DateTime  entryInLo gMethodTim e = DateTi me.UtcNow;
        84                if (Info World.Trac ing.IWTrac e.IsEntryE nabled)
        85                {
        86                    Info World.Trac ing.IWTrac e.Entry(Sy stem.Refle ction.Meth odBase.Get CurrentMet hod(), ent ryInLogMet hodTime);
        87                }
        88                try
        89                {
        90                    //by te[] encry ptBytes =  Encoding.B igEndianUn icode.GetB ytes(input );
        91                    byte [] encrypt Bytes = Co nvertFromA lphabetStr ing(input) ;
        92                    byte [] saltByt es = Encod ing.UTF8.G etBytes(en cryption_s altBytes);
        93  
        94                    // s ymmetric e ncryption  algorithm
        95                    usin g (AesMana ged aes =  new AesMan aged())
        96                    {
        97                         // Setting  our param eters
        98                         aes.BlockS ize = aes. LegalBlock Sizes[0].M axSize;
        99                         aes.KeySiz e = aes.Le galKeySize s[0].MaxSi ze;
        100  
        101                         // We're u sing the P BKDF2 stan dard for p assword-ba sed key ge neration
        102                         using (Rfc 2898Derive Bytes rfc  = new Rfc2 898DeriveB ytes(encry ptionPassw ord, saltB ytes))
        103                         {
        104                             aes.Ke y = rfc.Ge tBytes(aes .KeySize /  8);
        105                             aes.IV  = rfc.Get Bytes(aes. BlockSize  / 8);
        106                         }
        107  
        108                         // Now, de cryption
        109                         ICryptoTra nsform dec ryptTrans  = aes.Crea teDecrypto r();
        110  
        111                         // Output  stream, ca n be also  a FileStre am
        112                         using (Mem oryStream  decryptStr eam = new  MemoryStre am())
        113                         {
        114                             Crypto Stream dec ryptor = n ew CryptoS tream(decr yptStream,  decryptTr ans, Crypt oStreamMod e.Write);
        115  
        116                             decryp tor.Write( encryptByt es, 0, enc ryptBytes. Length);
        117                             decryp tor.Flush( );
        118                             decryp tor.FlushF inalBlock( ); //decry ptor.Close ();
        119  
        120                             // Sho wing our d ecrypted c ontent
        121                             byte[]  decryptBy tes = decr yptStream. ToArray();
        122                             string  decrypted String = U TF8Encodin g.UTF8.Get String(dec ryptBytes,  0, decryp tBytes.Len gth);
        123  
        124                             return  decrypted String;
        125                         }
        126                    }
        127                }
        128                finally
        129                {
        130                    if ( InfoWorld. Tracing.IW Trace.IsEx itEnabled)
        131                    {
        132                         InfoWorld. Tracing.IW Trace.Exit (System.Re flection.M ethodBase. GetCurrent Method(),  DateTime.U tcNow, ent ryInLogMet hodTime);
        133                    }
        134                }
        135           }
        136  
        137           co nst int si ze = 52;
        138           pu blic stati c string C onvertToAl phabetStri ng(byte[]  input)
        139           {
        140                DateTime  entryInLo gMethodTim e = DateTi me.UtcNow;
        141                if (Info World.Trac ing.IWTrac e.IsEntryE nabled)
        142                {
        143                    Info World.Trac ing.IWTrac e.Entry(Sy stem.Refle ction.Meth odBase.Get CurrentMet hod(), ent ryInLogMet hodTime);
        144                }
        145                try
        146                {
        147                    if ( input == n ull || inp ut.Length  == 0)
        148                         return Str ing.Empty;
        149                    Stri ngBuilder  sb = new S tringBuild er();
        150                    Syst em.Collect ions.IEnum erator ien  = input.G etEnumerat or();
        151                    byte  c1, c2;
        152  
        153                    whil e (ien.Mov eNext())
        154                    {
        155                         byte b = ( byte)ien.C urrent;
        156                         c1 = (byte )(b / 52);
        157                         c2 = (byte )(b % 52);
        158                         c1 = (byte )(c1 + 65) ;
        159                         c2 = (byte )(c2 <= 25  ? c2 + 65  : c2 + 71 );
        160  
        161                         sb.Append( (char)c1);
        162                         sb.Append( (char)c2);
        163                    }
        164                    retu rn sb.ToSt ring();
        165                }
        166                finally
        167                {
        168                    if ( InfoWorld. Tracing.IW Trace.IsEx itEnabled)
        169                    {
        170                         InfoWorld. Tracing.IW Trace.Exit (System.Re flection.M ethodBase. GetCurrent Method(),  DateTime.U tcNow, ent ryInLogMet hodTime);
        171                    }
        172                }
        173           }
        174           
        175           pu blic stati c byte[] C onvertFrom AlphabetSt ring(strin g input)
        176           {
        177                DateTime  entryInLo gMethodTim e = DateTi me.UtcNow;
        178                if (Info World.Trac ing.IWTrac e.IsEntryE nabled)
        179                {
        180                    Info World.Trac ing.IWTrac e.Entry(Sy stem.Refle ction.Meth odBase.Get CurrentMet hod(), ent ryInLogMet hodTime);
        181                }
        182                try
        183                {
        184                    if ( String.IsN ullOrEmpty (input))
        185                         return nul l;
        186                    byte [] rez = n ew byte[in put.Length  / 2];
        187                    Syst em.Collect ions.IEnum erator ien  = input.T oCharArray ().GetEnum erator();
        188                    int  i = 0;
        189                    whil e (ien.Mov eNext())
        190                    {
        191                         char c1 =  (char)ien. Current;
        192                         ien.MoveNe xt();
        193                         char c2 =  (char)ien. Current;
        194                         c1 = (char )(c1 - 65) ;
        195                         c2 = (char )(c2 <= 90  ? c2 - 65  : c2 - 71 );
        196  
        197                         rez[i++] =  (byte)(c1  * 52 + c2 );
        198  
        199                    }
        200                    retu rn rez;
        201                }
        202                finally
        203                {
        204                    if ( InfoWorld. Tracing.IW Trace.IsEx itEnabled)
        205                    {
        206                         InfoWorld. Tracing.IW Trace.Exit (System.Re flection.M ethodBase. GetCurrent Method(),  DateTime.U tcNow, ent ryInLogMet hodTime);
        207                    }
        208                }
        209           }
        210       }
        211   }