সেনসিটিভ স্ট্রিং (পাসওয়ার্ড, API কী, ইত্যাদি) বাইনারিতে সহজে পড়া না যাবে সেজন্য হেক্সাডেসিমাল (বা অন্য এনকোডিং) এ কনভার্ট করে রাখা যায়। এটি এনক্রিপশন নয়, কেবল অবফাসকেশন (obfuscation)।
পদ্ধতি: ASCII -> Hex এনকোড
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
using namespace std;
string to_hex(const string& input) {
stringstream ss;
for (unsigned char c : input)
ss << hex << setw(2) << setfill('0') << static_cast<int>(c);
return ss.str();
}
string from_hex(const string& hex) {
string result;
for (size_t i = 0; i < hex.length(); i += 2) {
string byte = hex.substr(i, 2);
result += static_cast<char>(stoi(byte, nullptr, 16));
}
return result;
}
int main() {
string secret = "This is a sample text";
string encoded = to_hex(secret);
cout << "Encoded: " << encoded << endl;
cout << "Decoded: " << from_hex(encoded) << endl;
return 0;
}
আউটপুট
Encoded: 5468697320697320612073616d706c652074657874 Decoded: This is a sample text
সিকিউরিটি নোট:
- এটি এনক্রিপশন নয় - কেউ সহজে ডিকোড করতে পারবে।
- সত্যিকারের সিকিউরিটির জন্য: AES এনক্রিপশন, সিকিউর কি ম্যানেজমেন্ট, হার্ডওয়ার সিকিউরিটি মডিউল (HSM) ব্যবহার করুন।
- রানটাইমে মেমরিতে ডিক্রিপ্টেড স্ট্রিং থাকবে, ডিবাগার/মেমরি ডাম্পে পাওয়া যাবে।
বेहতর পদ্ধতি: কম্পাইল-টাইম এনক্রিপশন (যেমন xorstr লাইব্রেরি, বা কাস্টম constexpr এনক্রিপশন) যাতে সোর্স/বাইনারিতে প্লেইনটেক্সট নেই।