这里的代码展示了如何在你的应用程序,从tutorial采取使用基于密码的加密(PBE)一个片断:
PBEKeySpec pbeKeySpec;
PBEParameterSpec pbeParamSpec;
SecretKeyFactory keyFac;
// Salt
byte[] salt = {
(byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
(byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
};
// Iteration count
int count = 20;
// Create PBE parameter set
pbeParamSpec = new PBEParameterSpec(salt, count);
// Prompt user for encryption password.
// Collect user password as char array (using the
// "readPasswd" method from above), and convert
// it into a SecretKey object, using a PBE key
// factory.
System.out.print("Enter encryption password: ");
System.out.flush();
pbeKeySpec = new PBEKeySpec(readPasswd(System.in));
keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
// Create PBE Cipher
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
// Initialize PBE Cipher with key and parameters
pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
// Our cleartext
byte[] cleartext = "This is another example".getBytes();
// Encrypt the cleartext
byte[] ciphertext = pbeCipher.doFinal(cleartext);
是密码(或密码短语),该应用程序提示不是选项? –
当你说“我只有我”时,你的意思是即使你的服务从不解密数据?也就是说,它只是将加密块返回给用户,并将其解密为客户端(如某些在线备份服务)?或者你的意思是你的应用仍然像现在这样运行,用户在没有额外的努力/配置客户端看到他们的数据,但幕后租户1的数据加密与租户2不同的关键? – ckhan
首先你说“管理员应该能够定义密钥”和“只有管理员应该知道密钥”;那么“我们如何让每个用户定义自己的密钥?”。这些似乎是不相容的。我错过了什么? –