當前位置: 首頁>>代碼示例>>Java>>正文


Java SHA1Impl類代碼示例

本文整理匯總了Java中org.apache.harmony.security.provider.crypto.SHA1Impl的典型用法代碼示例。如果您正苦於以下問題:Java SHA1Impl類的具體用法?Java SHA1Impl怎麽用?Java SHA1Impl使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SHA1Impl類屬於org.apache.harmony.security.provider.crypto包,在下文中一共展示了SHA1Impl類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateSeed

import org.apache.harmony.security.provider.crypto.SHA1Impl; //導入依賴的package包/類
private void updateSeed(byte[] bytes) {

        // on call:   "seed" contains current bytes and current hash;
        // on return: "seed" contains new current bytes and possibly new current hash
        //            if after adding, seed bytes overfill its buffer
        SHA1Impl.updateHash(seed, bytes, 0, bytes.length - 1);

        seedLength += bytes.length;
    }
 
開發者ID:shannah,項目名稱:cn1,代碼行數:10,代碼來源:SHA1PRNG_SecureRandomImpl.java

示例2: processDigest

import org.apache.harmony.security.provider.crypto.SHA1Impl; //導入依賴的package包/類
/**
 * The method performs final actions and invokes the "computeHash(int[])" method.
 * In case if there is no enough words in current frame
 * after processing its data, extra frame is prepared and 
 * the "computeHash(int[])" method is invoked second time. <BR>
 *
 * After processing, the method resets engine's state
 *
 * @param
 *       digest - byte array
 * @param
 *       offset - offset in digest
 */
private void processDigest(byte[] digest, int offset) {

    int i, j;         // implementation variables
    int lastWord;     //

    long nBits = messageLength <<3 ;  // length has to be calculated before padding

    engineUpdate( (byte) 0x80 );      // beginning byte in padding

    i = 0;                     // i contains number of beginning word for following loop

    lastWord = (buffer[BYTES_OFFSET] + 3)>>2 ;  // computing of # of full words by shifting
                                                // # of bytes

    // possible cases:
    //
    // - buffer[BYTES_OFFSET] == 0 - buffer frame is empty, 
    //                         padding byte was 64th in previous frame
    //                         current frame should contain only message's length
    //
    // - lastWord < 14 - two last, these are 14 & 15, words in 16 word frame are free;
    //                   no extra frame needed
    // - lastWord = 14 - only one last, namely 15-th, word in frame doesn't contain bytes;
    //                   extra frame is needed
    // - lastWord > 14 - last word in frame is not full; 
    //                   extra frame is needed

    if ( buffer[BYTES_OFFSET] != 0 ) {

        if ( lastWord < 15 ) {
            i = lastWord;
        } else {
            if ( lastWord == 15 ) {
                buffer[15] = 0;       // last word in frame is set to "0"
            }
            SHA1Impl.computeHash(buffer);
            i = 0;
        }
    }
    Arrays.fill(buffer, i, 14, 0);

    buffer[14] = (int)( nBits >>>32 );
    buffer[15] = (int)( nBits & 0xFFFFFFFF );
    SHA1Impl.computeHash(buffer);

    // converting 5-word frame into 20 bytes
    j = offset;
    for ( i = HASH_OFFSET; i < HASH_OFFSET +5; i++ ) {
        int k = buffer[i];
        digest[j  ] = (byte) ( k >>>24 );   // getting first  byte from left
        digest[j+1] = (byte) ( k >>>16 );   // getting second byte from left
        digest[j+2] = (byte) ( k >>> 8 );   // getting third  byte from left
        digest[j+3] = (byte) ( k       );   // getting fourth byte from left
        j += 4;
    }

    engineReset();
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:72,代碼來源:SHA1_MessageDigestImpl.java

示例3: engineUpdate

import org.apache.harmony.security.provider.crypto.SHA1Impl; //導入依賴的package包/類
/**
 * Updates current message. <BR>
 *
 * The method overrides "engineUpdate(byte[],int,int)" in class MessageDigestSpi. <BR>
 *
 * The method silently returns if "len" <= 0.
 *
 * @param
 *       input  a byte array
 * @param
 *       offset a number of first byte in the "input" array to use for updating
 * @param
 *       len    a number of bytes to use
 *
 * @throws NullPointerException     
 *                if null is passed to the "buf" argument
 *
 * @throws IllegalArgumentException 
 *                if offset > buf.length or len > buf.length or 
 *                (len + offset) > buf.length
 * @throws ArrayIndexOutOfBoundsException
 *                offset < 0
 */
protected void engineUpdate(byte[] input, int offset, int len) {

    if ( input == null ) {
        throw new IllegalArgumentException(Messages.getString("security.166"));  //$NON-NLS-1$
    }
    if ( len <= 0 ) {
        return;
    }
    if ( offset < 0 ) {
        throw new ArrayIndexOutOfBoundsException(Messages.getString("security.165", offset)); //$NON-NLS-1$
    }
    if ( offset > input.length || len > input.length || (len + offset) > input.length ) {
        throw new IllegalArgumentException(
           Messages.getString("security.167")); //$NON-NLS-1$
    }

    SHA1Impl.updateHash(buffer, input, offset, offset + len -1 );
    messageLength += len;
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:43,代碼來源:SHA1_MessageDigestImpl.java


注:本文中的org.apache.harmony.security.provider.crypto.SHA1Impl類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。