System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
Originally Published: 2015-07-13
Article Number
Applies To
RSA Product/Service Type: C# Client
Issue
System.OutOfMemoryException: Insufficient memory to continue the execution of the program. at System.Runtime.InteropServices.Marshal.AllocCoTaskMem(Int32 cb) at Rsa.KeyManagerClient.RkmBase.CreateKM_CS_IF_DATA(String string_data, Int32 int_data, Byte[] in_data, Int32 in_data_len, Byte[] in_data2, Int32 in_data2_len) at Rsa.KeyManagerClient.RkmBase.SetCSInterfaceData(SWIGTYPE_p_r_km_key_ctx_st key_ctx, SWIGTYPE_p_r_km_key_st key, String string_data, Int32 int_data, Byte[] in_data, Int32 in_data_len, Byte[] in_data2, Int32 in_data2_len) at Rsa.KeyManagerClient.RkmContext.EncryptByClass(String keyClass, Byte[] plainText, RkmCryptoFormatIdentifier format, RkmKey& key) at rkmcs_threaded.Program.singleEncrypt(RkmKey& key, Byte[] plainText) at System.Runtime.InteropServices.Marshal.AllocCoTaskMem(Int32 cb) at Rsa.KeyManagerClient.RkmBase.CreateKM_CS_IF_DATA(String string_data, Int32 int_data, Byte[] in_data, Int32 in_data_len, Byte[] in_data2, Int32 in_data2_len) at Rsa.KeyManagerClient.RkmBase.SetCSInterfaceData(SWIGTYPE_p_r_km_key_ctx_st key_ctx, SWIGTYPE_p_r_km_key_st key, String string_data, Int32 int_data, Byte[] in_data, Int32 in_data_len, Byte[] in_data2, Int32 in_data2_len) at Rsa.KeyManagerClient.RkmContext.EncryptByClass(String keyClass, Byte[] plainText, RkmCryptoFormatIdentifier format, RkmKey& key) at rkmcs_threaded.Program.singleEncrypt(RkmKey& key, Byte[] plainText)
Cause
Resolution
public static void EncryptionAndDecryptionReusingKey()
{
byte[] cipherText1;
byte[] decryptedData1;
byte[] cipherText2;
byte[] decryptedData2;
RkmKey encryptionKey;
RkmKey decryptionKey;
// Encrypt the first plaintext using a key retrieved by Key Class.
cipherText1 = kmContext.EncryptByClass(SampleUtility.SampleKeyClass, plainText, RkmCryptoFormatIdentifier.Default,
out encryptionKey);
// Encrypt the second plaintext using the key from the first encryption.
cipherText2 = encryptionKey.Encrypt(plainText2);
// Decrypt the first ciphertext using the key retrieved by key ID.
decryptedData1 = kmContext.DecryptByCipherText(cipherText1, out decryptionKey);
// Decrypt the second ciphertext using the key from the first decryption.
decryptedData2 = decryptionKey.Decrypt(cipherText2);
// Output the results.
DumpData("Result1", SampleUtility.StringToByteArray(plainText), cipherText1, decryptedData1);
DumpData("Result2", SampleUtility.StringToByteArray(plainText2), cipherText2, decryptedData2);
if (SampleUtility.ByteArrayToString(decryptedData1).CompareTo(plainText) != 0 ||
SampleUtility.ByteArrayToString(decryptedData2).CompareTo(plainText2) != 0)
{
throw new Exception("Decryption failed");
}
else
{
Console.WriteLine("Decryption succeeded");
}
// Clean up the extracted keys
encryptionKey.Dispose();
decryptionKey.Dispose();
}
Related Articles
RSA Identity Governance & Lifecycle Entitlements Data Collector (EDC) failure EC[31002] 112Number of Views Get Java Auth API sample code to authenticate consistently with 'Requires Name Lock' enabled 35Number of Views AFX failure when Proxy is enabled without defining Proxy Host or Port values in RSA Governance & Lifecycle 137Number of Views Data runs show error: Exception while executing filter query RSA Identity Governance & Lifecycle 6.8 and above 224Number of Views Error message "Error: java.lang.IllegalArgumentException: Window boundary must be positive" in the RSA SecurID Authenticat… 107Number of Views
Trending Articles
How to recover the Application and AFX after an unexpected database failure in RSA Identity Governance & Lifecycle Troubleshooting AFX Connector issues in RSA Identity Governance & Lifecycle RSA MFA Agent 2.3.6 for Microsoft Windows Installation and Administration Guide RSA Release Notes for RSA Authentication Manager 8.8 RSA Authentication Manager 8.9 Release Notes (January 2026)
Don't see what you're looking for?