我正在将一些 C# 代码转换为 Java。我找不到相当于RNGCryptoServiceProvider. 我该怎么做呢?
private static String GetRandomSalt()
{
RNGCryptoServiceProvider random = new RNGCryptoServiceProvider();
byte[] salt = new byte[32]; //256 bits
random.GetBytes(salt);
...
}
Run Code Online (Sandbox Code Playgroud)
To expand on my comment:
Java's SecureRandom is the equivalent you're looking for.
SecureRandom random = new SecureRandom();
byte[] salt = new byte[32];
random.nextBytes(salt);
Run Code Online (Sandbox Code Playgroud)
The documentation details some other ways to get an instance of SecureRandom, depending on your requirements.
| 归档时间: |
|
| 查看次数: |
1883 次 |
| 最近记录: |