当前位置: 首页>>代码示例>>Java>>正文


Java Cipher.DECRYPT_MODE属性代码示例

本文整理汇总了Java中com.sun.spotx.crypto.Cipher.DECRYPT_MODE属性的典型用法代码示例。如果您正苦于以下问题:Java Cipher.DECRYPT_MODE属性的具体用法?Java Cipher.DECRYPT_MODE怎么用?Java Cipher.DECRYPT_MODE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.sun.spotx.crypto.Cipher的用法示例。


在下文中一共展示了Cipher.DECRYPT_MODE属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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.DECRYPT_MODE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。