简体   繁体   English

Java中用于安全存储数据的最佳实践是什么?

[英]What is the best practices in Java for secure storage of data?

I have java application and I need save passwords into encrypted file. 我有java应用程序,我需要将密码保存到加密文件中。 I got advice to use Windows API. 我得到了使用Windows API的建议。 I found JDPAPI what is JNI wrapper around the MS DPAPI. 我发现JDPAPI是什么是MS DPAPI的JNI包装器。 It seems good. 看起来不错。 But I want to know does another libraries or methods exist to use Windows API for secure storage of data into file? 但我想知道是否存在使用Windows API将数据安全存储到文件中的其他库或方法? Or does some methods exist for secure storage in Java without using Windows API? 或者在不使用Windows API的情况下,是否存在一些用于Java安全存储的方法? I never use secure storage. 我从不使用安全存储。 Can you talk me about the best practices in Java for secure storage of data with and without Windows API? 你能谈谈Java中使用和不使用Windows API安全存储数据的最佳实践吗?

First: Using Windows API is kind of senseless. 第一:使用Windows API有点无意义。 Even when you can't imagine that, it might be possible that you have to migrate. 即使您无法想象,您也可能需要迁移。

Second: Storing a password encrypted only makes sense when you enter the encryption key during the applications runtime. 第二:只有在应用程序运行时输入加密密钥时才存储加密密码才有意义。 If you store it in a configuration file, it does not make any sense. 如果将它存储在配置文件中,则没有任何意义。

The encryption key could be stored as a thread local variable after it was entered. 加密密钥可以在输入后存储为线程局部变量。

I would suggest using property files and encrypt and decrypt the values in a service layer using bouncy castle. 我建议使用属性文件,并使用bouncy castle加密和解密服务层中的值。 This way you can mix encrypted and unencrypted values in the same file. 这样,您可以在同一文件中混合加密和未加密的值。

You could of course use Spring and do the necessary stuff quite easily using Spring security crypto. 您当然可以使用Spring并使用Spring安全加密技术轻松完成必要的操作。

In case we are talking of a web app using hibernate, I'd suggest using properties stored in a database and use jasypt for transparent encryption. 如果我们正在讨论使用hibernate的Web应用程序,我建议使用存储在数据库中的属性并使用jasypt进行透明加密。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM