我正在使用Eclipse.我有以下代码行:
wr.write(new sun.misc.BASE64Encoder().encode(buf));
Run Code Online (Sandbox Code Playgroud)
Eclipse将此行标记为错误.我导入了所需的库:
import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
Run Code Online (Sandbox Code Playgroud)
我使用Apache Commons作为建议的解决方案,包括:
import org.apache.commons.*;
Run Code Online (Sandbox Code Playgroud)
并导入从以下网址下载的JAR文件:http://commons.apache.org/codec/
但问题仍然存在.Eclipse仍然显示前面提到的错误; 请指教.
使用标准JDK在Java中生成安全随机AES密钥的推荐方法是什么?
在其他帖子中,我发现了这一点,但使用a SecretKeyFactory可能是一个更好的主意:
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
SecureRandom random = new SecureRandom(); // cryptograph. secure random
keyGen.init(random);
SecretKey secretKey = keyGen.generateKey();
Run Code Online (Sandbox Code Playgroud)
如果答案包括解释为什么它是生成随机密钥的好方法,那将是很好的.谢谢!
对于JAVA,是否有可靠的PBKDF2-HMAC-SHA256实现?
我以前用bouncycastle加密,但它没有提供PBKDF2WithHmacSHA256'.
我不想自己编写加密模块.
你能推荐任何替代的库或算法(如果我能坚持使用bouncycastle)
(这里是bouncycastle支持算法的算法) http://www.bouncycastle.org/specifications.html
我是密码学的新手.我希望学习如何加密和解密文件中的文本......当我在网上查阅相关文章时.我怀疑在同一文本上多次加密时加密文本对于单个文本是否相同?任何人都可以清楚我的怀疑吗?
我有一个应用程序需要在配置文件中存储一些秘密密码,如数据库和ftp密码/详细信息.我环顾四周,发现了许多使用AES的加密/解密解决方案,但我似乎无法弄清楚如何在不更改密钥的情况下使其工作.这意味着我可以加密和解密(使用相同的SecretKey),但是在重启等时保持持久性.我似乎无法使SecretKey保持不变.以下示例显示了我的方法:
String secret = Encryptor.encrpytString("This is secret");
String test = Encryptor.decrpytString(secret);
System.out.println(test); //This is secret is printed
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.但是,如果我运行它,我可能会得到'2Vhht/L80UlQ184S3rlAWw =='的值作为我的秘密,下次它是'MeC4zCf9S5wUUKAu8rvpCQ ==',所以可能关键是正在改变.我假设我正在对这个问题运用一些反直觉的逻辑,如果有人能够解释a)我做错了什么,或者b)允许我存储加密的密码信息的解决方案,我会很感激并可通过提供的信息检索.
我的方法如下:
private static final String salt = "SaltySalt";
private static byte [] ivBytes = null;
private static byte[] getSaltBytes() throws Exception {
return salt.getBytes("UTF-8");
}
private static char[] getMasterPassword() {
return "SuperSecretPassword".toCharArray();
}
private static byte[] getIvBytes() throws Exception {
if (ivBytes == null) {
//I don't have the parameters, so I'll generate a dummy encryption to create them
encrpytString("test"); …Run Code Online (Sandbox Code Playgroud) 我们在App中使用了一些Networkcredentials.我只是反编译应用程序,并能够看到名称和密码等凭据.我真的没有办法防止这种情况发生.我认为"混淆器"这个词是我必须走的方向.我们测试proguard但它没有字符串加密或我错了吗?
有一种简单而自由的方式来做到这一点吗?
谢谢.
我必须使用 AES -256 密码以及 AES 256 密钥和 16 字节 IV 来加密我的文件,我想将密钥和 IV 保存在一个文件中并重新使用它进行解密。但目前我可以单独保存它。任何人都可以帮助我们如何将密钥和 IV 存储在单个文件中。
这是我的代码
SecureRandom srandom = new SecureRandom();
byte[] iv = new byte[16];
srandom.nextBytes(iv);
IvParameterSpec ivspec = new IvParameterSpec(iv);
FileOutputStream ivOutFile = new FileOutputStream("C:\\iv.key");
ivOutFile.write(iv);
ivOutFile.close();
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(256);
SecretKey skey = kgen.generateKey();
FileOutputStream out = new FileOutputStream("C:\\AES.key");
byte[] keyb = skey.getEncoded();
out.write(keyb);
out.close();
Cipher ci = Cipher.getInstance("AES/CBC/PKCS5Padding");
ci.init(Cipher.ENCRYPT_MODE, skey, ivspec);
FileEncryptionUtils fileEncryptionUtils =new FileEncryptionUtils();
fileEncryptionUtils.processFile(ci, inFile, outFile);
Run Code Online (Sandbox Code Playgroud) 我正在使用:
1. RSA / ECB / PKCS1Padding
2. AES / GCM /无填充
在我的Android(Java)应用程序中加密我的数据。在SonarQube 的文档中指出:
高级加密标准(AES)加密算法可用于各种模式。不带填充的Galois /计数器模式(GCM)应优先于以下不安全的组合:
因此,根据建议,我AES/GCM/NoPadding用作:
Cipher c = Cipher.getInstance("AES/GCM/NoPadding");
Run Code Online (Sandbox Code Playgroud)
但是,它仍然会警告我确保此处加密数据是安全的。
相同的:
Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding");
Run Code Online (Sandbox Code Playgroud)
SonarQube为什么会发出该警告?这些用途不再安全吗?
java ×7
encryption ×5
aes ×4
aes-gcm ×1
base64 ×1
bouncycastle ×1
credentials ×1
cryptography ×1
jce ×1
obfuscation ×1
padding ×1
pbkdf2 ×1
rsa ×1