本文整理汇总了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);
}
示例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");
}
}
示例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();
}
}
示例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());
}
}
示例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");
}
}
示例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;
}
示例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);
}
示例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");
}
}
示例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;
}
示例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 ;
}
示例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;
}
示例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;
}
示例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();
}
示例15: createDecryptor
@Override
public Decryptor createDecryptor() throws GeneralSecurityException {
return new JceAesCtrCipher(Cipher.DECRYPT_MODE, provider);
}