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


Java Cipher.DECRYPT_MODE属性代码示例

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


在下文中一共展示了Cipher.DECRYPT_MODE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: engineInit

/**
 * Initialises this cipher with key and a source of randomness
 */
protected final void engineInit(int mode, Key key, SecureRandom random)
		throws InvalidKeyException {
	if (mode == Cipher.ENCRYPT_MODE)
		if (!(key instanceof PaillierPublicKey))
			throw new InvalidKeyException(
					"I didn't get a PaillierPublicKey. ");
		else if (mode == Cipher.DECRYPT_MODE)
			if (!(key instanceof PaillierPrivateKey))
				throw new InvalidKeyException(
						"I didn't get a PaillierPrivateKey. ");
			else
				throw new IllegalArgumentException("Bad mode: " + mode);

	stateMode = mode;
	keyPaillier = key;
	SECURE_RANDOM = random;
	int modulusLength = ((PaillierKey) key).getN().bitLength();
	calculateBlockSizes(modulusLength);
}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:22,代码来源:PaillierHomomorphicCipher.java

示例2: wolfCryptSetDirection

private void wolfCryptSetDirection(int opmode)
    throws InvalidKeyException {

    /* we don't currently support AES key wrap in JCE yet,
     * so don't allow WRAP_MODE or UNWRAP_MODE */
    switch (opmode) {
        case Cipher.ENCRYPT_MODE:
            this.direction = OpMode.WC_ENCRYPT;
            break;

        case Cipher.DECRYPT_MODE:
            this.direction = OpMode.WC_DECRYPT;
            break;

        default:
            throw new InvalidKeyException(
                "Cipher opmode must be ENCRYPT_MODE or DECRPYT_MODE");
    }
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:19,代码来源:WolfCryptCipher.java

示例3: GCMCipherLite

GCMCipherLite(Cipher cipher, SecretKey secreteKey, int cipherMode) {
    super(cipher, ContentCryptoScheme.AES_GCM, secreteKey, cipherMode);
    tagLen = cipherMode == Cipher.ENCRYPT_MODE ? TAG_LENGTH : 0;
    if (cipherMode != Cipher.ENCRYPT_MODE
            && cipherMode != Cipher.DECRYPT_MODE) {
        throw new IllegalArgumentException();
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:8,代码来源:GCMCipherLite.java

示例4: cryptData

protected byte[] cryptData(
    boolean forEncryption,
    AlgorithmIdentifier algId,
    char[] password,
    boolean wrongPKCS12Zero,
    byte[] data)
    throws IOException
{
    String algorithm = algId.getAlgorithm().getId();
    PKCS12PBEParams pbeParams = PKCS12PBEParams.getInstance(algId.getParameters());
    PBEKeySpec pbeSpec = new PBEKeySpec(password);

    try
    {
        SecretKeyFactory keyFact = SecretKeyFactory.getInstance(algorithm, bcProvider);
        PBEParameterSpec defParams = new PBEParameterSpec(
            pbeParams.getIV(),
            pbeParams.getIterations().intValue());
        BCPBEKey key = (BCPBEKey)keyFact.generateSecret(pbeSpec);

        key.setTryWrongPKCS12Zero(wrongPKCS12Zero);

        Cipher cipher = Cipher.getInstance(algorithm, bcProvider);
        int mode = forEncryption ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE;
        cipher.init(mode, key, defParams);
        return cipher.doFinal(data);
    }
    catch (Exception e)
    {
        throw new IOException("exception decrypting data - " + e.toString());
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:32,代码来源:PKCS12KeyStoreSpi.java

示例5: encryptOrDecrypt

public void encryptOrDecrypt(String key, int mode, InputStream is,
		OutputStream os) throws Exception {

	DESKeySpec dks = new DESKeySpec(key.getBytes());
	SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
	SecretKey desKey = skf.generateSecret(dks);
	Cipher cipher = Cipher.getInstance("DES"); // DES/ECB/PKCS5Padding for
	// SunJCE

	if (mode == Cipher.ENCRYPT_MODE) {
		cipher.init(Cipher.ENCRYPT_MODE, desKey);
		CipherInputStream cis = new CipherInputStream(is, cipher);
		doCopy(cis, os);
	} else if (mode == Cipher.DECRYPT_MODE) {
		cipher.init(Cipher.DECRYPT_MODE, desKey);
		CipherOutputStream cos = new CipherOutputStream(os, cipher);
		doCopy(is, cos);
	}
}
 
开发者ID:cyberheartmi9,项目名称:Mona-Secure-Multi-Owner-Data-Sharing-for-Dynamic-Group-in-the-Cloud,代码行数:19,代码来源:CipherExample.java

示例6: engineGetOutputSize

protected int engineGetOutputSize(
    int     inputLen) 
{
    if (state == Cipher.ENCRYPT_MODE || state == Cipher.WRAP_MODE)
    {
        return buffer.size() + inputLen + 20; /* SHA1 MAC size */
    }
    else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE)
    {
        return buffer.size() + inputLen - 20;
    }
    else
    {
        throw new IllegalStateException("cipher not initialised");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:16,代码来源:CipherSpi.java

示例7: engineTransformBlock

/**
 * This method is called whenever a full block needs to be
 * encrypted/decrypted. The input block is contained in input.The
 * transformed block is written into output starting at otputOfset. The
 * number of bytes written is returned.
 * 
 * @param input
 *            - byte[]
 * @param inputOffset
 *            -int
 * @param inputLenth
 *            -int
 * @param output
 *            -byte[]
 * @param outputOffset
 *            -int
 * @return The number of bytes written.
 * @throws ShortBufferException
 */
protected final int engineTransformBlock(byte[] input, int inputOffset,
		int inputLenth, byte[] output, int outputOffset)
		throws ShortBufferException {
	if (stateMode == Cipher.ENCRYPT_MODE)
		try {
			return encryptBlock(input, inputOffset, inputLenth, output,
					outputOffset);
		} catch (Exception e) {
			e.printStackTrace();
		}
	else if (stateMode == Cipher.DECRYPT_MODE)
		return decryptBlock(input, inputOffset, inputLenth, output,
				outputOffset);
	return 0;

}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:35,代码来源:PaillierCipher.java

示例8: engineInit

/**
 * Initialises this cipher with key and a source of randomness
 */
protected void engineInit(int mode, Key key, SecureRandom random)
		throws InvalidKeyException {
	if (mode == Cipher.ENCRYPT_MODE)
		if (!(key instanceof PaillierPublicKey))
			throw new InvalidKeyException(
					"I didn't get a PaillierPublicKey. ");
		else if (mode == Cipher.DECRYPT_MODE)
			if (!(key instanceof PaillierPrivateKey))
				throw new InvalidKeyException(
						"I didn't get a PaillierPrivateKey. ");
			else
				throw new IllegalArgumentException("Bad mode: " + mode);

	stateMode = mode;
	keyPaillier = key;
	SECURE_RANDOM = random;
	int modulusLength = ((PaillierKey) key).getN().bitLength();
	calculateBlockSizes(modulusLength);
}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:22,代码来源:PaillierCipher.java

示例9: engineGetOutputSize

protected int engineGetOutputSize(
    int     inputLen)
{
    if (state == Cipher.ENCRYPT_MODE || state == Cipher.WRAP_MODE)
    {
        return buffer.size() + inputLen + 20; /* SHA1 MAC size */
    }
    else if (state == Cipher.DECRYPT_MODE || state == Cipher.UNWRAP_MODE)
    {
        return buffer.size() + inputLen - 20;
    }
    else
    {
        throw new IllegalStateException("cipher not initialised");
    }
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:16,代码来源:JCEIESCipher.java

示例10: engineGetBlockSize

/**
 * engineGetBlockSize() returns the appropriate size , based on cipher.
 * 
 * @return plaintextSize - the block size(in bytes).
 */
protected int engineGetBlockSize() {
	if (stateMode == Cipher.DECRYPT_MODE)
		return ciphertextSize;
	else
		return plaintextSize;
}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:11,代码来源:PaillierCipher.java

示例11: engineGetBlockSize

/**
 * This method returns the appropriate block size , based on cipher.
 * 
 * @return BlockSize - the block size(in bytes).
 */
protected final int engineGetBlockSize() {
	if (stateMode == Cipher.DECRYPT_MODE)
		return ciphertextSize ;
	else
		return plaintextSize ;
}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:11,代码来源:PaillierHomomorphicCipher.java

示例12: rsaSplitCodec

private static byte[] rsaSplitCodec(Cipher cipher, int opmode, byte[] datas, int keySize){
    int maxBlock = 0;
    if(opmode == Cipher.DECRYPT_MODE){
        maxBlock = keySize / 8;
    }else{
        maxBlock = keySize / 8 - 11;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int offSet = 0;
    byte[] buff;
    int i = 0;
    try{
        while(datas.length > offSet){
            if(datas.length-offSet > maxBlock){
                buff = cipher.doFinal(datas, offSet, maxBlock);
            }else{
                buff = cipher.doFinal(datas, offSet, datas.length-offSet);
            }
            out.write(buff, 0, buff.length);
            i++;
            offSet = i * maxBlock;
        }
    }catch(Exception e){
        throw new RuntimeException("加解密阀值为["+maxBlock+"]的数据时发生异常", e);
    }
    byte[] resultDatas = out.toByteArray();
    IOUtils.closeQuietly(out);
    return resultDatas;
}
 
开发者ID:liamylian,项目名称:x-rsa,代码行数:29,代码来源:XRsa.java

示例13: open

@Override
public long open(DataSpec dataSpec) throws IOException {
  long dataLength = upstream.open(dataSpec);
  long nonce = CryptoUtil.getFNV64Hash(dataSpec.key);
  cipher = new AesFlushingCipher(Cipher.DECRYPT_MODE, secretKey, nonce,
      dataSpec.absoluteStreamPosition);
  return dataLength;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:8,代码来源:AesCipherDataSource.java

示例14: doFinal0

private final byte[] doFinal0(byte[] input, int inputOffset, int inputLen)
        throws IllegalBlockSizeException, BadPaddingException {
    if (doneFinal) {
        if (securityViolated)
            throw new SecurityException();
        if (Cipher.DECRYPT_MODE == getCipherMode())
            return finalBytes == null ? null : finalBytes.clone();
        // final bytes must have been previously computed via encryption
        int finalDataLen = finalBytes.length - tagLen;
        if (inputLen == finalDataLen)
            return finalBytes.clone();
        if (inputLen < finalDataLen) {
            if (inputLen + currentCount == outputByteCount) {
                int from = finalBytes.length - tagLen - inputLen;
                return Arrays.copyOfRange(finalBytes, from, finalBytes.length);
            }
        }
        throw new IllegalStateException("Inconsistent re-rencryption");
    }
    doneFinal = true;
    // compute final bytes for the first time
    finalBytes = super.doFinal(input, inputOffset, inputLen);
    if (finalBytes == null)
        return null;    // only possible for decryption
    outputByteCount += checkMax(finalBytes.length - tagLen);
    return finalBytes.clone();
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:27,代码来源:GCMCipherLite.java

示例15: createDecryptor

@Override
public Decryptor createDecryptor() throws GeneralSecurityException {
  return new JceAesCtrCipher(Cipher.DECRYPT_MODE, provider);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:4,代码来源:JceAesCtrCryptoCodec.java


注:本文中的javax.crypto.Cipher.DECRYPT_MODE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。