在java中创建一个受密码保护的文件 [英] Create a file protected by a password in java

查看:103
本文介绍了在java中创建一个受密码保护的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在JAVA中创建一个受密码保护的文件。
我的意思是,一旦我启动程序,我的程序创建的一个文件将被以前确定的密码直接保护。



有没有简单的方法做到这一点?

再一次,我的目标不是创建一个文件,然后添加一个密码,而是在创建过程中通过密码保护文件。
实际上,如果他/她已经设置了密码,我希望当前的亚军程序不能读取/编辑创建的文件。



因此,无论如何,如果你们中的一些人知道用java保护文件的简单方法,我将非常感激。



一天!

解决方案

你想用密码加密你的文件(的内容)。这是一个非常有名的图书馆: http://www.jasypt.org/



从他们的网站:

  ..加密和解密文本... 

BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword(myEncryptionPassword);
字符串myEncryptedText = textEncryptor.encrypt(myText);
...
String plainText = textEncryptor.decrypt(myEncryptedText);

您可以将加密内容读取/写入文件。

I would like to create a file protected by a password in JAVA. What I mean is, once I launch the program, one file created by my program would be directly protected by previously determined password.

Is there an easy way to do it ?

Once again, my aim is not to create a file and then add it a password, but right during the creation protecting the file by a password. Actually, I want the current runner program not having access in reading/editing the created file EXCEPT if he/she has the password previously set.

So anyway, if some of you know an easy way to protect files when writing them thanks to java, I would be most grateful.

Have a nice day!

解决方案

You want to encrypt your file('s content) with a password. Here is a pretty well known library to do it: http://www.jasypt.org/

From their site:

..encrypting and decrypting a text...

BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword(myEncryptionPassword);
String myEncryptedText = textEncryptor.encrypt(myText);
...
String plainText = textEncryptor.decrypt(myEncryptedText);

You can read/write the encrypted content to your file.

这篇关于在java中创建一个受密码保护的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆