检查pst文件是否受java-libpst密码保护 [英] check if a pst file is password protected with java-libpst

查看:209
本文介绍了检查pst文件是否受java-libpst密码保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用开源库 java-libpst 来解析外观pst file.在解析之前,我想知道该文件是否受密码保护.问题是我们这个库打开了没有密码的受密码保护的文件,所以我没有找到任何方法来检查该文件是否受密码保护.

我可以为此目的使用任何其他Java库,只要它们是开源的即可.

解决方案

在受密码保护的pst文件中,实际上没有进行任何加密.pst文件的密码是根据标识符0x67FF存储的.如果没有密码,则存储的值是0x00000000.打开pst文件时,此密码与Outlook匹配.由于这个原因,java库java-libpst也可以访问受密码保护的文件的所有内容,而无需实际使用密码.

要使用java-libpst检查文件是否受密码保护,请使用以下命令:

     /**
     * checks if a pst file is password protected
     * 
     * @param file - pst file to check 
     * @return - true if protected,false otherwise
     * 
     * pstfile has the password stored against identifier 0x67FF.
     * if there is no password the value stored is 0x00000000.
     */
    private static boolean ifProtected(PSTFile file,boolean reomovePwd){
        try {
            String fileDetails = file.getMessageStore().getDetails();
            String[] lines = fileDetails.split("\n");
            for(String line:lines){
                if(line.contains("0x67FF")){
                    if(line.contains("0x00000000"))
                        return false;
                    else
                        return true;
                }

            }
        } catch (PSTException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }

I am using the open source library java-libpst to parse a outlook pst file.before parsing I want to know if the file is password protected or not.The problem us that this library opens password protected files without password,so I did not find any way to check if the file is password protected.

I can use any other java library for this purpose,provided they are open source.

解决方案

In password protected pst files, ,nothing is actually encrypted .The Password of a pst file is stored against identifier 0x67FF.If there is no password the value stored is 0x00000000.This password is matched by outlook while opening pst file.Due to this reason,The java library java-libpst can also access all contents of password protected files without the actual need of password.

To check if the file is password protected,using java-libpst use this:

     /**
     * checks if a pst file is password protected
     * 
     * @param file - pst file to check 
     * @return - true if protected,false otherwise
     * 
     * pstfile has the password stored against identifier 0x67FF.
     * if there is no password the value stored is 0x00000000.
     */
    private static boolean ifProtected(PSTFile file,boolean reomovePwd){
        try {
            String fileDetails = file.getMessageStore().getDetails();
            String[] lines = fileDetails.split("\n");
            for(String line:lines){
                if(line.contains("0x67FF")){
                    if(line.contains("0x00000000"))
                        return false;
                    else
                        return true;
                }

            }
        } catch (PSTException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }

这篇关于检查pst文件是否受java-libpst密码保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆