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


Java Cipher.ENCRYPT_MODE屬性代碼示例

本文整理匯總了Java中com.sun.spotx.crypto.Cipher.ENCRYPT_MODE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Cipher.ENCRYPT_MODE屬性的具體用法?Java Cipher.ENCRYPT_MODE怎麽用?Java Cipher.ENCRYPT_MODE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在com.sun.spotx.crypto.Cipher的用法示例。


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

示例1: engineInit

/**
    * Initializes this cipher with a key and a set of algorithm
    * parameters.
    *
    * @param opMode the operation mode of this cipher
    * @param key the encryption key
    * @param params the algorithm parameters
    *
    * @exception java.security.InvalidKeyException if the given key
    * is inappropriate for initializing this cipher
    * @exception java.security.InvalidAlgorithmParameterException
    * if the given algorithm parameters are inappropriate for this cipher
    * @exception IllegalArgumentException if opMode is incorrect
    */
   protected void engineInit(int opMode, Key key, AlgorithmParameterSpec params)
           throws InvalidKeyException, InvalidAlgorithmParameterException {

if (params!=null) 
    throw new InvalidAlgorithmParameterException(RSA_ALGORITHM_NAME+" does not support AlgorithmParameterSpec. Must be null."); 

       if (!(key instanceof RSAKey)) {
           throw new InvalidKeyException();
       }

       if (opMode != Cipher.DECRYPT_MODE && opMode != Cipher.ENCRYPT_MODE) {
           throw new IllegalArgumentException("Wrong operation mode");
       }

       mode = opMode;
       ckey = (RSAKey)key;

       if (ckey.getModulusLen() == 0) {
           throw new InvalidKeyException();
       }

       messageToSign = new byte[ckey.getModulusLen()];
       bytesInMessage = 0;
   }
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:38,代碼來源:RSA.java

示例2: engineInit

protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params)
throws InvalidKeyException, InvalidAlgorithmParameterException {


    initOk = false;
    if (!(key instanceof SecretKeySpec)) {
        throw new InvalidKeyException("Key is not of required type SecretKey.");
    }
    if ((opmode != Cipher.ENCRYPT_MODE) && (opmode != Cipher.DECRYPT_MODE)) {
        throw new IllegalArgumentException("Unsupported mode.");
    }
	
    if (params instanceof IvParameterSpec) {
        ivParameter=(IvParameterSpec)params;
        if (!modeCBC) {
    	throw new InvalidAlgorithmParameterException("AlgorithmParameterSpec must be null for "+ALG1+" in ECB mode.");
        }
    } else if (params!=null) {
        throw new InvalidAlgorithmParameterException("AlgorithmParameterSpec params has to be null or IvParamater. Is: "+params.getClass().getName());
    }
    
    if (modeCBC) {
        IV = new int[4];
        if (ivParameter == null) {
            clearIV();
        } else {
    	unpackBlock(ivParameter.getIV(), 0, IV); 
        }
    }
    
    mode = opmode;
    this.key = (SecretKeySpec)key;

    generateWorkingKey(this.key.getEncoded(), (mode == Cipher.ENCRYPT_MODE)); 
    initOk = true;
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:36,代碼來源:Alg1.java

示例3: engineUpdate

protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws IllegalStateException, ShortBufferException {
    if ((inputLen < 0) || ((inputLen % BLOCK_SIZE) != 0) ||
    (inputOffset + inputLen > input.length) ||
    (outputOffset + inputLen > output.length))
		throw new ShortBufferException();

if (!initOk) {
    throw new IllegalStateException();
       }
       
       int res = inputLen;
       int lastC0 = 0, lastC1 = 0, lastC2 = 0, lastC3 = 0;
       
       while (inputLen > 0) {
           if (mode == Cipher.ENCRYPT_MODE) {
               unpackBlock(input, inputOffset, C);
               if (modeCBC) {
                   C[0] ^= IV[0]; C[1] ^= IV[1]; C[2] ^= IV[2]; C[3] ^= IV[3];
               }
               encryptBlock(workingKey);
               if (modeCBC) {
                   IV[0] = C[0]; IV[1] = C[1]; IV[2] = C[2]; IV[3] = C[3];
               }
               packBlock(output, outputOffset, C);
           } else {
               unpackBlock(input, inputOffset, C);
               if (modeCBC) {
                   // remember cipher block. this will be our next IV
                   lastC0 = C[0]; lastC1 = C[1]; lastC2 = C[2]; lastC3 = C[3];
               }
               decryptBlock(workingKey);
               if (modeCBC) {
                   C[0] ^= IV[0]; C[1] ^= IV[1]; C[2] ^= IV[2]; C[3] ^= IV[3];
                   IV[0] = lastC0; IV[1] = lastC1; IV[2] = lastC2; IV[3] = lastC3;
               }
               packBlock(output, outputOffset, C);
           }
           inputOffset += BLOCK_SIZE;
           outputOffset += BLOCK_SIZE;
           inputLen -= BLOCK_SIZE;
       }
       
       return res;
   }
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:44,代碼來源:Alg1.java

示例4: engineInit

protected void engineInit(int theMode, Key theKey, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException {
if (params!=null) 
    throw new InvalidAlgorithmParameterException(ALG2+" does not support AlgorithmParameterSpec. Must be null"); 
if (!(theKey instanceof SecretKeySpec)) {
    throw new InvalidKeyException();
}
 if   ((theMode != Cipher.ENCRYPT_MODE) && 
     (theMode != Cipher.DECRYPT_MODE)) {
    throw new InvalidAlgorithmParameterException();	    
    //CryptoException.throwIt(CryptoException.ILLEGAL_VALUE);
}
       /*if (!theKey.isInitialized()) {
    CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY);
       }*/

this.mode = theMode;
       this.key = theKey;
       
byte[] K = ((SecretKeySpec)theKey).getEncoded();
       int kLen = ((SecretKeySpec)theKey).getEncoded().length;

/* Initialize S */
for (int i = 0; i < 256; i++) {
           S[i] = (byte) i;
       }

int j = 0;
       int k = 0;
byte temp;
for (int i = 0; i < 256; i++) {
    j = (j + ((S[i] + K[k]) & 0xff)) & 0xff;
    temp = S[i];
    S[i] = S[j];
    S[j] = temp;
           if (++k >= kLen) k = 0;
}
       
       jj = ii = 0;
       
       initOk = true;
       needsReset = false;
   }
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:42,代碼來源:Alg2.java


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