SonarQube:确保加密数据在这里是安全的。 AES/GCM/NoPadding、RSA/ECB/PKCS1Padding

SonarQube: Make sure that encrypting data is safe here. AES/GCM/NoPadding, RSA/ECB/PKCS1Padding

我正在使用:

1. RSA/ECB/PKCS1Padding

2。 AES/GCM/NoPadding

在我的 Android (Java) 应用程序中加密我的数据。在 SonarQube 的 documentation 中指出:

高级加密标准 (AES) 加密算法可用于各种模式。 Galois/Counter 没有填充的模式 (GCM) 应该优先于以下不安全的组合:

因此,推荐,我使用 AES/GCM/NoPadding 作为 :

Cipher c = Cipher.getInstance("AES/GCM/NoPadding");

但是,它仍然给我警告确保加密数据在这里是安全的。

同样适用于:

Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding");

为什么 SonarQube 会抛出该警告? 这些用途不再安全了吗?

这似乎是关于加密任何数据的一般性警告。 "AES/GCM/NoPadding" 应该没有问题,因为 shown in their test code

GCM 模式下的 AES 作为分组密码算法是安全的。但这并不能保证使用 AES(在 GCM 模式下)加密数据的代码是安全的。有几件事可能会出错,使代码容易受到攻击。开发人员有责任以正确的方式对其进行编码以获得所需的安全级别。一些可能出错的例子是:

  1. 给定键的 IV 重复
  2. 密钥或原始数据以String数据类型存储在堆中
  3. 密钥以明文形式存储在代码存储库中的 属性 文件中

等等。

现在,SonarQube 无法识别所有这些漏洞,因此他们提出了一个名为 Hotspot 的新概念,here 描述为:

Unlike Vulnerabilities, Security Hotspots aren't necessarily issues that are open to attack. Instead, Security Hotspots highlight security-sensitive pieces of code that need to be manually reviewed. Upon review, you'll either find a Vulnerability that needs to be fixed or that there is no threat.

热点有一个单独的生命周期,这在上面给出的 link 中有解释。

P.S。这个答案解释了如何以安全的方式在 GCM 模式下使用 AES 加密 Java 中的字符串: