📄 sha1verification.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SHA1Verification.java
package org.gudy.azureus2.core3.util.test;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Random;
import org.gudy.azureus2.core3.util.*;
public class SHA1Verification
{
public static final String dirname = (new StringBuilder()).append("D:").append(System.getProperty("file.separator")).append("testdir").toString();
public SHA1Verification()
{
}
public static void main(String args[])
{
if (!(new File(dirname)).exists())
createTestFiles();
runTests();
}
public static void createTestFiles()
{
try
{
System.out.println("Creating test files ... ");
Random rand = new Random();
String rootname = "f-";
long sizes[] = {
0L, 1L, 0x2faf080L
};
File testdir = new File(dirname);
FileUtil.mkdirs(testdir);
for (int i = 0; i < sizes.length; i++)
{
long size = sizes[i];
File file = new File(testdir, (new StringBuilder()).append(rootname).append(String.valueOf(size)).toString());
System.out.println((new StringBuilder()).append(file.getName()).append("...").toString());
FileChannel fc = (new RandomAccessFile(file, "rw")).getChannel();
ByteBuffer bb;
for (long position = 0L; position < size; position += fc.write(bb))
{
long remaining = size - position;
if (remaining > 0xfa000L)
remaining = 0xfa000L;
byte buffer[] = new byte[(new Long(remaining)).intValue()];
rand.nextBytes(buffer);
bb = ByteBuffer.wrap(buffer);
}
fc.close();
}
System.out.println("DONE\n");
}
catch (Exception e)
{
Debug.printStackTrace(e);
}
}
public static void runTests()
{
try
{
MessageDigest sha1Sun = MessageDigest.getInstance("SHA-1");
SHA1 sha1Gudy = new SHA1();
ByteBuffer buffer = ByteBuffer.allocate(0x100000);
File dir = new File(dirname);
File files[] = dir.listFiles();
for (int i = 0; i < files.length; i++)
{
FileChannel fc = (new RandomAccessFile(files[i], "r")).getChannel();
System.out.println((new StringBuilder()).append("Testing ").append(files[i].getName()).append(" ...").toString());
for (; fc.position() < fc.size(); buffer.clear())
{
fc.read(buffer);
buffer.flip();
byte raw[] = new byte[buffer.limit()];
System.arraycopy(buffer.array(), 0, raw, 0, raw.length);
sha1Gudy.update(buffer);
sha1Gudy.saveState();
ByteBuffer bb = ByteBuffer.wrap(new byte[56081]);
sha1Gudy.digest(bb);
sha1Gudy.restoreState();
sha1Sun.update(raw);
}
byte sun[] = sha1Sun.digest();
sha1Sun.reset();
byte gudy[] = sha1Gudy.digest();
sha1Gudy.reset();
if (Arrays.equals(sun, gudy))
System.out.println(" SHA1-Gudy: OK");
else
System.out.println(" SHA1-Gudy: FAILED");
buffer.clear();
fc.close();
System.out.println();
}
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -