Java Security SealedObject decode
import java.io.FileInputStream; import java.io.ObjectInputStream; import java.security.KeyStore; import java.security.PrivateKey; import javax.crypto.SealedObject; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; ///*from www. ja v a 2 s .co m*/ public class Main { public static void main(String args[]) throws Exception { ObjectInputStream ois = new ObjectInputStream(new FileInputStream("key")); SealedObject so = (SealedObject) ois.readObject(); char[] password = "123456".toCharArray(); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(new FileInputStream("test.ks"), password); PrivateKey pri = (PrivateKey) ks.getKey("test", password); byte[] bytes = (byte[]) so.getObject(pri); ois = new ObjectInputStream(new FileInputStream("data")); so = (SealedObject) ois.readObject(); SecretKey sk = new SecretKeySpec(bytes, 0, bytes.length, so.getAlgorithm()); System.out.println(so.getObject(sk)); } }