简体   繁体   English

用Java加密解密数据

[英]Encrypt Decrypt data in Java

I have developed Rest web services in Java which takes Passwords and sensitive data from request body.我已经用 Java 开发了 Rest Web 服务,它从请求正文中获取密码和敏感数据。 How can I decrypt these data from my side and request sender can also enrypt at their end in same way?我怎样才能从我这边解密这些数据,并且请求发件人也可以以同样的方式在他们的末尾加密?

Basically by changing your design to use end-to-end encryption, via TLS.基本上是通过 TLS 更改您的设计以使用端到端加密。

In other words, you ensure that all your services can only be used the "https".换句话说,您确保您的所有服务只能使用“https”。

But that is a pretty broad topic, and details depend on the underlying framework your are using.但这是一个相当广泛的主题,细节取决于您使用的底层框架。 Here is some reading for Spring/J2EE , and here with Spring and Jersey , or there for Oracle WebLogic .这里有一些关于Spring/J2EE 的读物,这里有Spring 和 Jersey ,或者那里有Oracle WebLogic

Why not simply use jayspt library for simple encrypt or decrpyt.为什么不简单地使用jayspt库进行简单的加密或解密。

Here is the source code for encrypting data:这是加密数据的源代码:

String seedValue = "11241313xyz";
String mySecretStringshhh = "#soIsc00l123";

StandardPBEStringEncryptor stringEncryptor = new StandardPBEStringEncryptor();
stringEncryptor.setPassword(seedValue);
String encrypted= stringEncryptor.encrypt(mySecretStringshhh);

And for decryption:并用于解密:

StandardPBEStringEncryptor stringEncryptor = new StandardPBEStringEncryptor();
stringEncryptor.setPassword(seedValue);

String decryptedPassword = stringEncryptor.decrypt(encryptedpwdString);

Write a test case and have fun...写一个测试用例,玩得开心……

Further reference - http://www.jasypt.org/encrypting-passwords.html进一步参考 - http://www.jasypt.org/encrypting-passwords.html

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

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