当前位置: 首页>>代码示例>>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;未经允许,请勿转载。