English 中文(简体)
如何从加密字符串中获取 IV, 然后使用 AES128 解密该字符串
原标题:How to retrieve IV from an Encrypted string, then decrypt that string using AES128

我对加密知之甚少,但我的目标是解密字符串。我得到了AES(128)的密钥。

然而,我必须从加密的字符串中取回IV, 这是前16位数。

此处为销售人员获取更多信息(如果我解释的不正确)的参考文件。

Encrypts the blob clearText using the specified algorithm and private key. Use this method when you want Salesforce to generate the initialization vector for you. It is stored as the first 128 bits (16 bytes) of the encrypted blob

http://www.salesforce.com/us/ developmenter/docs/apexcode/Content/apex_classes_restful_cripto.htm>>http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_clases_restful_cripto.htm (加密无疑)

为了取回IV, 我尝试过这样的东西(但我不认为这是正确的):

public string retrieveIv()
        {
            string iv = "";
            string input = "bwZ6nKpBEsuAKM8lDTYH1Yl69KkHN1i3XehALbfgUqY=";
            byte[] bytesToEncode = Encoding.UTF8.GetBytes(input);

            for(int i = 0; i <= 15; i++){
                iv += bytesToEncode[i].ToString(); ;
            }

            return iv;
        }

(只要忽略输入是硬编码而不是参数化的这一事实;为测试目的更容易)

然后使用此 < a href=" https://stackoverflow.com/ questions/202011/ encrypt- decrypt- decrypt-string- in-net" 标题 = “ question” 问题 < question 解密字符串

最佳回答

IV不应以字符串表示 - 它应该以字节数组表示, 如 < a href=" http://msdn.microsoft.com/en-us/library/system.security.cryptgraphy. iv.aspx" rel="nofollow"\\\code>AesManaged.IV 属性 。

另外,使用 Encoding.UTF8 几乎肯定是错误的。 我怀疑您想要:

public static byte[] RetrieveIv(string encryptedBase64)
{
    // We don t need to base64-decode everything... just 16 bytes-worth
    encryptedBase64 = encryptedBase64.Substring(0, 24);

    // This will be 18 bytes long (4 characters per 3 bytes)
    byte[] encryptedBinary = Convert.FromBase64String(encryptedBase64);
    byte[] iv = new byte[16];

    Array.Copy(encryptedBinary, 0, iv, 0, 16);
    return iv;
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签