校验和保持时间戳的完整性

时间:2018-04-23 12:24:43

标签: java date checksum

我的时间戳基本上是" ddMMYYHHMMss"。我想要做的是每次我运行程序秒值改变但我的校验和保持不变。谁能帮我这个。我希望每当秒(时间)改变时校验和就会改变。

public class Checksum {
public static void main(String[] args) throws IOException {
    File f = new File("D:/test.txt");
    PrintWriter pw = new PrintWriter(f);
    if(!f.exists()){
        f.createNewFile();
    }
    Date d = new Date();
    SimpleDateFormat sd = new SimpleDateFormat("ddMMYYHHmmss");
    String formatteddate = sd.format(d);
    System.out.println(formatteddate);
    pw.println(formatteddate);
    pw.close();

    BufferedReader br = new BufferedReader(new FileReader(f));
    String line = null;

    while((line = br.readLine()) != null){
        break;
    }
    br.close();

    System.out.println("MD5    : " + toHex(Hash.MD5.checksum(line)));
    System.out.println("SHA1   : " + toHex(Hash.SHA1.checksum(line)));
    System.out.println("SHA256 : " + toHex(Hash.SHA256.checksum(line)));
    System.out.println("SHA512 : " + toHex(Hash.SHA512.checksum(line)));
}
 private static String toHex(byte[] bytes) {
        return DatatypeConverter.printHexBinary(bytes);
    }
}

class CheckSumGenerator {
public enum Hash {

    MD5("MD5"), SHA1("SHA1"), SHA256("SHA-256"), SHA512("SHA-512");

    private String name;

    Hash(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public byte[] checksum(String input) {
        try {
            MessageDigest digest = MessageDigest.getInstance(getName());
            byte[] block = new byte[4096];
            int length;
            if (input.length()> 0) {
                digest.update(block, 0, input.length());
            }
            return digest.digest();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}

}

1 个答案:

答案 0 :(得分:2)

您实际上从未将> d <- density(na.omit(x),n=1e4) > xmax <- d$x[d$y==max(d$y)] > x1 <- d$x[d$x < xmax][which.min(abs(d$y[d$x < xmax]-max(d$y)/2))] > x2 <- d$x[d$x > xmax][which.min(abs(d$y[d$x > xmax]-max(d$y)/2))] > points(c(x1, x2), c(d$y[d$x==x1], d$y[d$x==x2]), col="red") > (FWHM <- x2-x1) [1] 43.37897 传递给input来电。您总是传递相同的空字节数组:digest.update(...)因此它将始终返回相同的