c#中对int等基础数据类型进行封装加密

为了防止游戏过程中被第三方应用搜索到真实数据信息,我们需要对基础数据类型进行二次封装并加密。

基本思想就是设置一个密码,然后与真实数据进行异或操作。

为了使用方便,可以对运算符进行重载,这样就可以像使用基本数据类型一样使用了。

直接上代码:

public struct AHInt
{
    private static int cryptoKey = 123456;

    private int currentCryptoKey;
    private int hiddenValue;

    public int v
    {
        get { return InternalEncryptDecrypt(); }
        set { currentCryptoKey = cryptoKey; hiddenValue = EncryptDecrypt(value); }
    }

    public AHInt(int value)
    {
        currentCryptoKey = cryptoKey;
        hiddenValue = EncryptDecrypt(value);
    }

    public static void SetNewCryptoKey(int newKey)
    {
        cryptoKey = newKey;
    }

    public int GetEncrypted()
    {
        if (currentCryptoKey != cryptoKey)
        {
            hiddenValue = InternalEncryptDecrypt();
            hiddenValue = EncryptDecrypt(hiddenValue, cryptoKey);
            curre
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值