• AES简单解密


    某app返回内容进行了加密处理

    其本地解密实现如下

        @NotNull
        public final String decrypt(@NotNull String str, @NotNull String str2) {
            Intrinsics.checkParameterIsNotNull(str, "input");
            Intrinsics.checkParameterIsNotNull(str2, "key");
            Cipher instance = Cipher.getInstance("AES/CBC/NoPadding");
            Object bytes = str2.getBytes(Charsets.UTF_8);
            Intrinsics.checkExpressionValueIsNotNull(bytes, "(this as java.lang.String).getBytes(charset)");
            SecretKeySpec secretKeySpec = new SecretKeySpec(bytes, "AES");
            Object bytes2 = str2.getBytes(Charsets.UTF_8);
            Intrinsics.checkExpressionValueIsNotNull(bytes2, "(this as java.lang.String).getBytes(charset)");
            instance.init(2, secretKeySpec, new IvParameterSpec(bytes2));
            Object doFinal = instance.doFinal(Base64.decode(str, 0));
            Intrinsics.checkExpressionValueIsNotNull(doFinal, "encrypt");
            return StringsKt.trim(new String(doFinal, Charsets.UTF_8), new char[]{'u0000'});
        }

    key值为一个写死的字符串

    参数有两个 str //加密后的字符串  str2 //解密需要的 key

    另偏移向量为 str2 utf8 的字节数组

    实现如下 

    function decrypt($str, $key)
    {
        if([string]::IsNullOrEmpty($str)){return $null}
        $toEncryptArray=[Convert]::FromBase64String($str)
        $ivArray=[Text.Encoding]::UTF8.GetBytes($key)
        $rm=[System.Security.Cryptography.RijndaelManaged]::new()
            $rm.Key=[Text.Encoding]::UTF8.GetBytes($key)
            $rm.IV=$ivArray
            $rm.Mode=[System.Security.Cryptography.CipherMode]::CBC
            $rm.Padding=[System.Security.Cryptography.PaddingMode]::None
        $cTransform=$rm.CreateDecryptor()
        $resultArray=$cTransform.TransformFinalBlock($toEncryptArray,0,$toEncryptArray.length)
        return [Text.Encoding]::UTF8.GetString($resultArray).Trim()
    }
  • 相关阅读:
    项目管理【53】 | 项目风险管理-规划风险应对
    Learning a Continuous Representation of 3D Molecular Structures with Deep Generative Models
    转:DenseNet
    转:期刊投稿中的简写(ADM,AE,EIC等)与流程状态解读
    论文中如何写算法伪代码
    氨基酸,多肽,蛋白质等
    pytorch查看全连接层的权重和梯度
    AI制药文章
    long-tail datasets
    转:Focal Loss理解
  • 原文地址:https://www.cnblogs.com/feiyucha/p/12516302.html
Copyright © 2020-2023  润新知