java openssl

public void testDESBytes3() throws Exception {
    /*
    char[] pwd = {'!', 'E', 'i', 'k', 'o', '?'};
        byte[] enc = OpenSSL.encrypt("des", pwd, "全世界无产阶级者联合起来".getBytes());
        System.out.println(Arrays.toString(enc));
        byte[] dec = OpenSSL.decrypt("des", pwd, enc);
        System.out.println(new String(dec));


     */
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("c:/des-cfb8.raw"));
    ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
    byte[] temp = new byte[1024];
    int size = 0;
    while ((size = in.read(temp)) != -1) {
        out.write(temp, 0, size);
    }
    in.close();

    byte[] content = out.toByteArray();

    char[] pwd = "changeit".toCharArray();
    System.out.println("Readed bytes count:" + content.length);
   // byte[] encrypted = Util.streamToBytes(in);
    //String cipher = "fileName.substring(0, x)";
    String cipher ="des-cfb8";
    byte[] result = OpenSSL.decrypt(cipher, pwd, content);
    String s = new String(result, "ISO-8859-1");
    System.out.println(s);
    System.out.println("hello,world");
    }

  

posted on 2020-11-23 22:14  lydstory  阅读(356)  评论(0)    收藏  举报

导航