CNG is slow?

Not quite sure why, but CNG (Cryptography-Next-Generation) is considerably slower than good old RSACryptoServiceProvider:

MethodKeySizeMeanErrorStdDev
RSAEncrypt5127.304 μs7.521 μs0.4122 μs
RSADecrypt51231.200 μs3.130 μs0.1715 μs
RSACngEncrypt512142.589 μs8.738 μs0.4790 μs
RSACngDecrypt512184.463 μs36.394 μs1.9949 μs

There could be several reasons why CNG (Cryptography-Next-Generation) is slower than RSACryptoServiceProvider. Here are some possibilities:

  1. Algorithmic Differences: CNG uses different cryptographic algorithms than RSACryptoServiceProvider. Depending on the specific algorithms being used, CNG may be slower due to increased computational complexity or the need for additional calculations.
  2. Key Size: CNG may be using larger key sizes than RSACryptoServiceProvider, which can result in slower performance due to increased computational complexity.
  3. Hardware Acceleration: RSACryptoServiceProvider may be leveraging hardware acceleration, such as the Intel Advanced Encryption Standard (AES) instruction set, which can significantly speed up encryption and decryption operations. CNG may not be utilizing hardware acceleration to the same extent.
  4. Implementation Differences: The specific implementation of CNG or RSACryptoServiceProvider that you are using could be impacting performance. For example, if CNG is being used in a managed code environment such as C# or VB.NET, it may be slower due to the overhead of the .NET runtime.

It’s worth noting that while CNG may be slower than RSACryptoServiceProvider in certain scenarios, it is generally considered to be a more modern and secure encryption technology. Additionally, CNG offers other benefits such as support for elliptic curve cryptography and better performance on multi-core processors.

RSACryptoServiceProvider is a class in the .NET Framework that provides RSA encryption functionality.

Cryptography-Next-Generation (CNG) is a modern encryption technology introduced in Windows Vista that offers improved security and performance over previous cryptographic APIs.


To contact me, send an email anytime or leave a comment below.