Blog Layout

Web.Config Base64 Encoding With Simple Salt (and decoding)

E.DIN Editor • Nov 17, 2021

Title: Base64 Encoding With Simple Salt (and decoding)


Console App-

...App.config

  <appSettings>

    <add key="SoapHeader" value="http://mySvc.com:7147/ws/evoCorp/Header" />

    <add key="SoapLines" value="http://mySvc.com:7147/ws/evoCorp/Lines" />

    <add key="SoapPosted" value="http://mySvc.com:7147/ws/evoCorp/Posted" />

<add key="domainName" value="myDomain" />

<add key="domainUser" value="myServiceUser"/> 

<add key="domainHash" value="myServiceAuth"/>

<add key="domainMode" value="test"/>

  </appSettings>


...Program.cs

 
  using 
 System;
using  System.Collections.Generic;
using  System.IO;
using  System.Linq;
using  System.Text;

namespace  ConsoleBase64x
{
     internal   class   Program
    {
         static   int   Main ( string []  args )
        {   
             //"8>4D>?]aX+#+A2k" EncodeWithoutSalt = OD40RD4/XWFYKyMrQTJr
             //"8>4D>?]aX+#+A2k" EncodeWithSalt = MTU4PjREPj9dYVgrIytBMms=
             Console. WriteLine ( "Enter the setting name in the app.config to encrypt the setting's value. Ex: domainHash. Then press {enter}." );
             var   sKeyName  =  Console. ReadLine ();
             if  ( string. IsNullOrEmpty ( sKeyName ))
            {
                Console. WriteLine ( "The setting name in the app.config was not found or was empty. The program will now exit." );
                Console. Read ();
                 return  -1; 
            }
             var   sHashword  =  SettingsConfigHelper. GetAppSetting ( sKeyName );
             Console. WriteLine ( "original: "  +  sHashword );
             var   sHashword64encoded  =  SettingsConfigHelper. Base64EncodeWithSalt ( sHashword );
             Console. WriteLine ( "Base64EncodeWithSalt: "  +  sHashword64encoded );
             Console. WriteLine ( "Highlight the value above, copy it to notepad, and Press any key to decode back to original value." );
             Console. Read ();
             var   sHashwordDecoded  =  SettingsConfigHelper. Base64DecodeWithSalt ( sHashword64encoded );
             Console. WriteLine ( "Base64DecodeWithSalt: "  +  sHashwordDecoded );
             Console. WriteLine ( "If this value is the same as the original value in the App.Config, you can use it in the Control Console Web.Config." );
             Console. WriteLine ( "Press any key to exit." );
             Console. Read ();
             Console. Read ();
             return  0;

             //byte[] imageBytes = SettingsConfigHelper.FromBase64Bytes(sHashword);
             //var fstrm = new FileStream(@"C:\winnt_copy.bmp", FileMode.CreateNew, FileAccess.Write);
             //BinaryWriter writer = new BinaryWriter(fstrm);
             //Console.Write(imageBytes);
             //writer.Close( );
        }

    }
}
 
 ...SettingsConfigHelper.cs 
 
 
  using 
 System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Text;

namespace  ConsoleBase64x
{
      public   static   class   SettingsConfigHelper
    {

         /* GET CONFIG KEY VALUE */
         public   static   string   GetAppSetting ( string   sKey
        {
             if  ( sKey  ==  null )
            {
                 return   null ;
            }
             var   sValue  = System.Configuration. ConfigurationManager.AppSettings[ sKey ];
             return   sValue  ??  string.Empty;
        }
         /* ENCODE STRING */
         public   static   string   Base64Encode ( string   plainText
        {
             if  ( plainText  ==  null )
            {
                 return   null ;
            }
             var   plainTextBytes  = System.Text. Encoding.UTF8. GetBytes ( plainText );
             return  System. Convert. ToBase64String ( plainTextBytes );
        }
         /* DECODE STRING */
         public   static   string   Base64Decode ( string   base64EncodedData
        {
             if  ( base64EncodedData  ==  null )
            {
                 return   null ;
            }
             var   base64EncodedBytes  = System. Convert. FromBase64String ( base64EncodedData );
             return  System.Text. Encoding.ASCII. GetString ( base64EncodedBytes );
        }

         /* ENCODE STRING with salt */
         public   static   string   Base64EncodeWithSalt ( string   plainText
        {
             if  ( plainText  ==  null )
            {
                 return   null ;
            }
             var   iLen  =  plainText.Length;
             var   sLen  =  "00" ;
             if  ( iLen  < 10) 
            {
                 sLen  =  string. Concat ( "0"iLen. ToString ());
            }
             else
            {
                 sLen  =  iLen. ToString ();
            }
             var   plainTextBytes  = System.Text. Encoding.UTF8. GetBytes ( sLen  +  plainText );
             return  System. Convert. ToBase64String ( plainTextBytes );
        }
         /* DECODE STRING with salt*/
         public   static   string   Base64DecodeWithSalt ( string   base64EncodedData
        {
             if  ( base64EncodedData  ==  null )
            {
                 return   null ;
            }
             var   base64EncodedBytes  = System. Convert. FromBase64String ( base64EncodedData );
             var   sValue  = System.Text. Encoding.ASCII. GetString ( base64EncodedBytes );
             sValue  =  sValue. Substring (2);
             return   sValue ;
        }


         /* Decoding an encoded base64 string by using static Convert.FromBase64CharArray method. 
         * This method returns a byte[] that contains the decoded elements of the string.
         * If you receive a file via email, such as an image file (.bmp), that has previously been converted to a string, 
         * to convert it back into its original bitmap file, you could do something like the following:
         */

         public   static   byte []  Base64DecodeString ( string   inputStr
        {
             byte []  decodedByteArray  =  Convert. FromBase64CharArray ( inputStr. ToCharArray (), 0,  inputStr.Length);
             return  ( decodedByteArray );
        }

         /* Convert a Base64 encoded string into a byte[] use Convert.FromBase64String 
         * Base64 is always ascii text. So just do Encoding.ASCII.GetString(base64arr)
         */

         public   static   byte []  FromBase64Bytes ( this   byte []  base64Bytes )
        {
             string   base64String  =  Encoding.UTF8. GetString ( base64Bytes , 0,  base64Bytes.Length);
             return   Convert. FromBase64String ( base64String );
        }

    }
 }









By E.DIN Editor 17 Nov, 2021
XPCMD_SHELL Move & Load Data from Directory
By E.DIN Editor 17 Nov, 2021
By E.DIN Editor 17 Nov, 2021
By E.DIN Editor 01 Oct, 2020
 ***** My Valid Data Monitor **** XML OUT *** HTML EMAIL DELIVERY  *****IF OBJECT_ID('tempdb..#tCustomerID') IS NOT NULL DROP TABLE #tCustomerID    select distinct         mm.CustomerID  Into #tCustomerID    from myDatabase..myTable (nolock) mm     left join myDatabase.dbo.myOtherTable (nolock) mo  on mm.refID = mo.id     left join myDatabase.dbo.myOtherTableDetail (nolock) mod  on mo.id = mod.myOtherTableid         and mm.SearchValue = mod.SearchValue     where mm.refID is not null     and mm.quantity is not null      and mod.SearchValue is nullIF Exists (Select 1 From #tCustomerID)BEGIN DECLARE @xml NVARCHAR(MAX)DECLARE @body NVARCHAR(MAX)SET @xml = CAST(( SELECT [CustomerID] AS 'td' FROM #tCustomerID ORDER BY CustomerID FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))SET @body ='

My Valid Data Monitor

'    SET @body = @body + @xml +'
CustomerID
'--SELECT @body  exec msdb.dbo.sp_send_dbmail  @profile_name  = 'dbmailProfile' ,@recipients    = 'usergroup@mydomain.com' ,@subject       = 'My Valid Data Monitor' ,@body          = @body ,@body_format   = 'HTML'END
By websitebuilder 20 Sep, 2020
The new season is a great reason to make and keep resolutions. Whether it’s eating right or cleaning out the garage, here are some tips for making and keeping resolutions.
By websitebuilder 20 Sep, 2020
There are so many good reasons to communicate with site visitors. Tell them about sales and new products or update them with tips and information.
By websitebuilder 20 Sep, 2020
Write about something you know. If you don’t know much about a specific topic that will interest your readers, invite an expert to write about it.
By tekp 15 Jul, 2020
Turn Up! Not every microphone has the same base volume for transmitting your voice through your computer to whoever or whatever is on the other end of the exchange. Some microphones have a higher volume as compared to others, and some microphones have a volume that is so low that the person on the other […] The post How to Turn Up Mic Volume in Windows 10 – Appuals.com appeared first on TekPreacher.
By E.DIN Editor 09 Jun, 2020
'+@UNCPathAndLogTable+'
By E.DIN Editor 14 May, 2020
--UNIQUE AND RANDOM TRANSACTION NAMES (FOR HIGH VOLUME TRANSACTIONS PER SECOND)DECLARE @randomString VARCHAR(255) = CONVERT(varchar(255), NEWID());SELECT @randomString = replace(replace(replace(convert(varchar, getdate(), 120),':',''),'-',''),' ','') + RIGHT(@randomString,10);PRINT ''+ CONVERT(VARCHAR,LEN(@randomString)) + ' CHARS / OF MAXIMUM 32 CHARS FOR LENGTH OF TRANSACTION NAMES'SELECT @randomStringBEGIN TRANSACTION  @randomStringSELECT replace(replace(replace(convert(varchar, getdate(), 120),':',''),'-',''),' ','');SELECT CONVERT(VARCHAR,getdate(),112) + LEFT(REPLACE(CONVERT(VARCHAR,getdate(),114),':',''),6);SELECT REPLACE(SUBSTRING(CONVERT(VARCHAR(33),SYSDATETIMEOFFSET(),126), 1, 8), '-', '') + SUBSTRING(REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(33), SYSDATETIMEOFFSET(), 126),'T',''),'.',''),':',''),9,DATALENGTH(CONVERT(VARCHAR(33), SYSDATETIMEOFFSET(), 126)))COMMIT TRANSACTION  @randomStringOUTPUT-- 24 CHARS / OF MAXIMUM 32 CHARS FOR LENGTH OF TRANSACTION NAMES-- 202005141039592610925CAA  <- THIS IS THE ONE-- 20200514103959-- 20200514103959-- 202005141039598866412-0500
More Posts
Share by: