[Implement] 簡單密碼加密解密

[Implement] 簡單密碼加密解密

string passUTF8_1 = "abcd1234"; //初始密碼
byte[] passByteArr_byUTF8 = Encoding.UTF8.GetBytes(passUTF8_1); //將密碼轉成Byte陣列
string passBase64 = Convert.ToBase64String(passByteArr_byUTF8); //將Byte陣列轉成Base64字碼
//passBase64  = "YWJjZDEyMzQ="
string reversePass = ReverseString(passBase64);  //簡單增加密碼破解(將密碼顛倒)
//reversePass  = "=QzMyEDZjJWY"


//解密
string reversePass = ReverseString(reversePass);  //簡單增加密碼破解(將密碼顛倒)
byte[] passByteArr_byBase64 = Convert.FromBase64String(reversePass);
string passUTF8_2 = System.Text.Encoding.UTF8.GetString(passByteArr_byBase64);
//passUTF8_2: "abcd1234"


public string ReverseString(string targetStr)
{
    char[] charArray = targetStr.ToCharArray();
    Array.Reverse(charArray); 
    string result = string.Empty;
    foreach (char c in charArray)
    {
        result += c; //output: "=QzMyEDZjJWY"
    }
    
    return result ;
}