Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
CDigest.java
Package: security.rar [view]
Upload User: lior1029
Upload Date: 2013-05-07
Package Size: 209k
Code Size: 2k
Category:
CA program
Development Platform:
Java
- package org.infosecurity.cryptography;
- import org.infosecurity.cryptography.*;
- /**
- * <p>Title: 摘要算法的抽象类 </p>
- * <p>Description: 摘要算法的抽象类 </p>
- * <p>Copyright: Copyright (c) 2003</p>
- * <p>Company:bouncycastle org </p>
- */
- public abstract class CDigest
- implements IDigest
- {
- private byte[] xBuf;
- private int xBufOff;
- private long byteCount;
- // 1.构造
- protected CDigest()
- {
- xBuf = new byte[4];
- xBufOff = 0;
- }
- protected CDigest(CDigest t)
- {
- xBuf = new byte[t.xBuf.length];
- System.arraycopy(t.xBuf, 0, xBuf, 0, t.xBuf.length);
- xBufOff = t.xBufOff;
- byteCount = t.byteCount;
- }
- // 2.输入一个字节的数据
- public void update(
- byte in)
- {
- xBuf[xBufOff++] = in;
- // 填充满一个4个字节了
- if (xBufOff == xBuf.length)
- {
- processWord(xBuf, 0);
- xBufOff = 0;
- }
- byteCount++;
- }
- public void update(
- byte[] in,
- int inOff,
- int len)
- {
- //
- // fill the current word
- //
- while ((xBufOff != 0) && (len > 0))
- {
- update(in[inOff]);
- inOff++;
- len--;
- }
- //
- // process whole words.
- //
- while (len > xBuf.length)
- {
- processWord(in, inOff);
- inOff += xBuf.length;
- len -= xBuf.length;
- byteCount += xBuf.length;
- }
- //
- // load in the remainder.
- //
- while (len > 0)
- {
- update(in[inOff]);
- inOff++;
- len--;
- }
- }
- // 3.完成
- public void finish()
- {
- // 每一个字节是8位
- long bitLength = (byteCount << 3);
- //
- // 附加填充比特一个1,多个0,直到len mod 512 = 448
- //1000,0000B=128
- update((byte)128);
- while (xBufOff != 0)
- {
- update((byte)0);
- }
- // 最后填充8字节(64bit)的长度信息
- processLength(bitLength);
- // 处理最后一块
- processBlock();
- }
- public void reset()
- {
- byteCount = 0;
- xBufOff = 0;
- for ( int i = 0; i < xBuf.length; i++ ) {
- xBuf[i] = 0;
- }
- }
- protected abstract void processWord(byte[] in, int inOff);
- protected abstract void processLength(long bitLength);
- protected abstract void processBlock();
- }