有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

加密如何在java中加密和解密对象?

我需要用java加密和解密一个对象,这样我就可以知道是谁加密了它。 比如物体上的数字签名

范例-

class Animal{
    public String name;

    public Animal(String name){
         this.name = name;
    }
}

class Client {
    public int id;
    // some more fields
    public void encrypt(Animal a){
        // some implementation
    }

    public Client(int id) {
        this.id = id;
    }
}

class Main{
   public static void main(String[] args) {
       Animal lion = new Animal("Lion");
       Client client1 = new Client(1);
       Client client2 = new Client(2);
       SomeClass c1 = client1.encrypt(lion);
       SomeClass c2 = client2.encrypt(lion);
       // let's say I have the keys corresponding to client1 and client2
       // now I want to get back the lion object from c1 and c2.
   }
}

我想要一对钥匙,公钥和私钥。联机阅读有关使用公钥进行加密和使用私钥进行解密的信息

我使用了错误的方法,使用公钥进行加密,只公开私钥进行解密,我在网上读到的内容是不推荐的

我希望客户机类对对象进行加密,然后公开一些密钥,这些密钥可以解密该客户机加密的对象


共 (0) 个答案