用C#加密,用Apex解密
我想将查询字符串中的一个字段从asp.net传递到Apex。我想加密字段的值,然后将其传递到查询字符串中。 我不知道如何处理这个问题,是否有相同的示例代码/链接? 基本上我想用C#加密,用Apex解密 在C中#用C#加密,用Apex解密,c#,.net,salesforce,apex-code,C#,.net,Salesforce,Apex Code,我想将查询字符串中的一个字段从asp.net传递到Apex。我想加密字段的值,然后将其传递到查询字符串中。 我不知道如何处理这个问题,是否有相同的示例代码/链接? 基本上我想用C#加密,用Apex解密 在C中# 但这不起作用,decryptedData.toString()不是“测试”(原始文本)。如何将其解密回来?为什么?无论如何,与SF的所有通信都是通过SSL完成的(例如) 如果您必须这样做,Apex有一个支持多种算法的类。希望您能在C#库中找到匹配的 如果您需要传递一些二进制数据(例如ba
但这不起作用,decryptedData.toString()不是“测试”(原始文本)。如何将其解密回来?为什么?无论如何,与SF的所有通信都是通过SSL完成的(例如) 如果您必须这样做,Apex有一个支持多种算法的类。希望您能在C#库中找到匹配的
如果您需要传递一些二进制数据(例如base64),那么还有一个类。创建上述示例的人非常接近。如果他们加密了一个比“Test”更长的字符串,他们可能会意识到这一点——他们只需要在加密内容的前面插入一些填充: 字符串spadding=“paddingxxxxxxxxx”; 字符串源=spadding+Opportunity0065 --输出应该是“Opportunity0065”
static string key = "eU5WzoFgU4n8Apu5PYxcNGRZswRDZJWDEMdbQVU85gw=";
static string IV = "9ehY9gYtfIGlLRgwqg6F2g==";
static void Main(string[] args)
{
string source = "test";
string encrypted = EncryptStringToBytes_Aes(source, Convert.FromBase64String(key), Convert.FromBase64String(IV));
Console.ReadLine();
}
static string EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
{
// Check arguments.
if (plainText == null || plainText.Length <= 0)
throw new ArgumentNullException("plainText");
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
if (IV == null || IV.Length <= 0)
throw new ArgumentNullException("Key");
string encrypted;
// Create an AesManaged object
// with the specified key and IV.
using (AesManaged aesAlg = new AesManaged())
{
aesAlg.Key = Key;
aesAlg.IV = IV;
// Create a decrytor to perform the stream transform.
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
// Create the streams used for encryption.
using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
//Write all data to the stream.
swEncrypt.Write(plainText);
}
encrypted = Convert.ToBase64String(msEncrypt.ToArray());// ToArray();
}
}
}
// Return the encrypted bytes from the memory stream.
return encrypted;
}
string cryptoKey='eU5WzoFgU4n8Apu5PYxcNGRZswRDZJWDEMdbQVU85gw=';
String det= System.currentPageReference().getParameters().get('Det');
Blob decryptedData = Crypto.decryptWithManagedIV('AES256', EncodingUtil.base64Decode(cryptoKey), EncodingUtil.base64Decode(det));