0

クエリ文字列のフィールドを asp .net から Apex に渡したいです。フィールドの値を暗号化して、クエリ文字列に渡したいです。これにアプローチする方法がわかりません。同じコード/リンクの例はありますか? 基本的には、C# で暗号化し、Apex を使用して復号化したいと考えています。

C# の場合

 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));

しかし、これは機能しません。decryptedData.toString() は 'test' (元のテキスト) になりません。どうすれば復号化できますか?

4

2 に答える 2

0

なんで?とにかく、SF とのすべての通信は SSL 経由で行われます (たとえば、https://salesforce.stackexchange.com/questions/8273/data-loader-cli-and-encryption )。

絶対に必要な場合 - Apex には、いくつかのアルゴリズムをサポートするCryptoクラスがあります。うまくいけば、C# ライブラリで一致するものを見つけることができます。

バイナリ データを渡す必要がある場合は、EncodingUtilクラスもあります (base64 など)。

于 2013-04-16T17:30:10.943 に答える