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


Java NoSuchPaddingException类代码示例

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


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

示例1: createTheCipherInstance

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
/**
 * Creates the Cipher Instance.
 */
private static Cipher createTheCipherInstance(int opMode, String transformation, Key key)
{
    try
    {
        Cipher cipher = Cipher.getInstance(transformation);
        cipher.init(opMode, key);
        return cipher;
    }
    catch (InvalidKeyException invalidkeyexception)
    {
        invalidkeyexception.printStackTrace();
    }
    catch (NoSuchAlgorithmException nosuchalgorithmexception)
    {
        nosuchalgorithmexception.printStackTrace();
    }
    catch (NoSuchPaddingException nosuchpaddingexception)
    {
        nosuchpaddingexception.printStackTrace();
    }

    LOGGER.error("Cipher creation failed!");
    return null;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:28,代码来源:CryptManager.java

示例2: decrypt

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
public String decrypt(String str) {
    Cipher cipher;
    try {
        cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, keySpec,
                new IvParameterSpec(ips.getBytes("UTF-8")));

        byte[] byteStr = Base64.decodeBase64(str.getBytes());
        String Str = new String(cipher.doFinal(byteStr), "UTF-8");

        return Str;
    } catch (NoSuchAlgorithmException | NoSuchPaddingException
            | InvalidKeyException | InvalidAlgorithmParameterException
            | IllegalBlockSizeException | BadPaddingException
            | UnsupportedEncodingException e) {
    }
    return null;
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:19,代码来源:AES256.java

示例3: runAll

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
public void runAll() throws InvalidKeyException,
        NoSuchPaddingException, InvalidAlgorithmParameterException,
        ShortBufferException, IllegalBlockSizeException,
        BadPaddingException, NoSuchAlgorithmException,
        NoSuchProviderException {

    for (String mode : MODES) {
        for (String padding : PADDINGS) {
            if (!isMultipleKeyLengthSupported()) {
                runTest(mode, padding, minKeySize);
            } else {
                int keySize = maxKeySize;
                while (keySize >= minKeySize) {
                    out.println("With Key Strength: " + keySize);
                    runTest(mode, padding, keySize);
                    keySize -= KEYCUTTER;
                }
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:TestCipher.java

示例4: decrypt

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
public static String decrypt(String str) {
    if (str == null) return null;
    Cipher cipher;
    try {
        cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, keySpec,
                new IvParameterSpec(ips.getBytes("UTF-8")));

        byte[] byteStr = Base64.decodeBase64(str.getBytes());
        String Str = new String(cipher.doFinal(byteStr), "UTF-8");

        return Str;
    } catch (NoSuchAlgorithmException | NoSuchPaddingException
            | InvalidKeyException | InvalidAlgorithmParameterException
            | IllegalBlockSizeException | BadPaddingException
            | UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:21,代码来源:AES256.java

示例5: testProviderInstallationAtRuntime

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
@BeforeClass
public static void testProviderInstallationAtRuntime()
    throws NoSuchProviderException, NoSuchPaddingException {

    /* install wolfJCE provider at runtime */
    Security.addProvider(new WolfCryptProvider());

    Provider p = Security.getProvider("wolfJCE");
    assertNotNull(p);

    /* populate enabledJCEAlgos to test */
    for (int i = 0; i < supportedJCEAlgos.length; i++) {
        try {
            Cipher c = Cipher.getInstance(supportedJCEAlgos[i], "wolfJCE");
            enabledJCEAlgos.add(supportedJCEAlgos[i]);

        } catch (NoSuchAlgorithmException e) {
            /* algorithm not enabled */
        }
    }

    /* fill expected block size HashMap */
    expectedBlockSizes.put("AES/CBC/NoPadding", 16);
    expectedBlockSizes.put("DESede/CBC/NoPadding", 8);
    expectedBlockSizes.put("RSA/ECB/PKCS1Padding", 0);
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:27,代码来源:WolfCryptCipherTest.java

示例6: encrypt

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
/**
 * 加密方法
 * 
 * @param rawKeyData
 * @param str
 * @return
 * @throws InvalidKeyException
 * @throws NoSuchAlgorithmException
 * @throws IllegalBlockSizeException
 * @throws BadPaddingException
 * @throws NoSuchPaddingException
 * @throws InvalidKeySpecException
 */
public static byte[] encrypt(byte rawKeyData[], String str) throws InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException,
		BadPaddingException, NoSuchPaddingException, InvalidKeySpecException {
	// DES算法要求有一个可信任的随机数源
	SecureRandom sr = new SecureRandom();
	// 从原始密匙数据创建一个DESKeySpec对象
	DESKeySpec dks = new DESKeySpec(rawKeyData);
	// 创建一个密匙工厂,然后用它把DESKeySpec转换成一个SecretKey对象
	SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
	SecretKey key = keyFactory.generateSecret(dks);
	// Cipher对象实际完成加密操作
	Cipher cipher = Cipher.getInstance("DES");
	// 用密匙初始化Cipher对象
	cipher.init(Cipher.ENCRYPT_MODE, key, sr);
	// 现在,获取数据并加密
	byte data[] = str.getBytes();
	// 正式执行加密操作
	byte[] encryptedData = cipher.doFinal(data);

	System.out.println("加密后===>" + encryptedData);
	return encryptedData;
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:35,代码来源:EncryptDecryptData.java

示例7: getInstance

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
public static MeviusTransferPacket getInstance(PublicKey publickey, MeviusPacket packet)
		throws MeviusCipherException {
	try {
		DESedeKeySpec desKeySpec = new DESedeKeySpec(((String) MeviusCipherKey.randomDESKey().getKey()).getBytes());
		SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
		Key key = keyFactory.generateSecret(desKeySpec);
		Cipher c = Cipher.getInstance("RSA/ECB/PKCS1PADDING", "SunJCE");
		c.init(Cipher.ENCRYPT_MODE, publickey);
		byte[] bkey = convertObj(key, c);
		c = Cipher.getInstance("DESede/ECB/PKCS5Padding");
		c.init(Cipher.ENCRYPT_MODE, key);
		byte[] bobj = convertObj(packet, c);
		return new MeviusTransferPacket(bkey, bobj);
	} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException
			| IOException | InvalidKeySpecException | IllegalBlockSizeException | BadPaddingException e) {
		e.printStackTrace();
		throw new MeviusCipherException(e.getLocalizedMessage());
	}
}
 
开发者ID:biancso,项目名称:Mevius-IO,代码行数:20,代码来源:MeviusTransferPacket.java

示例8: wrapperPublicPriviteKeyTest

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
private void wrapperPublicPriviteKeyTest(Provider p, String[] algorithms)
        throws NoSuchAlgorithmException, InvalidKeyException,
        NoSuchPaddingException, IllegalBlockSizeException,
        InvalidAlgorithmParameterException {
    for (String algo : algorithms) {
        // Key pair generated
        System.out.println("Generate key pair (algorithm: " + algo
                + ", provider: " + p.getName() + ")");
        KeyPairGenerator kpg = KeyPairGenerator.getInstance(algo);
        kpg.initialize(512);
        KeyPair kp = kpg.genKeyPair();
        // key generated
        String algoWrap = "DES";
        KeyGenerator kg = KeyGenerator.getInstance(algoWrap, p);
        Key key = kg.generateKey();
        wrapTest(algo, algoWrap, key, kp.getPrivate(), Cipher.PRIVATE_KEY,
                false);
        wrapTest(algo, algoWrap, key, kp.getPublic(), Cipher.PUBLIC_KEY,
                false);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:TestCipherKeyWrapperTest.java

示例9: engineSetPadding

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
@Override
protected void engineSetPadding(String padding)
		throws NoSuchPaddingException {
	
	if ( ! mIsInited ) {
		NativeLib.init();
	}
	
	if ( padding.length() == 0 ) {
		return;
	}

	if ( ! padding.equals("PKCS5Padding") ) {
		throw new NoSuchPaddingException("Only supports PKCS5Padding.");
	}
	
	mPadding = true;
		
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:20,代码来源:NativeAESCipherSpi.java

示例10: getKey

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
public Key getKey(PrivateKey privatekey) throws MeviusCipherException {
	try {
		Cipher c = Cipher.getInstance("RSA/ECB/PKCS1PADDING", "SunJCE");
		c.init(Cipher.DECRYPT_MODE, privatekey);
		/*
		 * DESedeKeySpec desKeySpec = new DESedeKeySpec((byte[]) (convertByte(key, c)));
		 * SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede"); return
		 * keyFactory.generateSecret(desKeySpec);
		 */
		return (Key) convertByte(key, c);
	} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException
			| ClassNotFoundException | IOException | IllegalBlockSizeException | BadPaddingException e) {
		e.printStackTrace();
		throw new MeviusCipherException(e.getMessage());
	}
}
 
开发者ID:biancso,项目名称:Mevius-IO,代码行数:17,代码来源:MeviusTransferPacket.java

示例11: encrypt

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
/**
 * this method is used to encrypt the password.
 * 
 * @param value String password
 * @param encryption_key
 * @return encrypted password.
 * @throws NoSuchPaddingException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeyException
 * @throws BadPaddingException
 * @throws IllegalBlockSizeException
 */
@SuppressWarnings("restriction")
public static String encrypt(String value) throws NoSuchAlgorithmException,
    NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
  encryption_key = getSalt();
  Key key = generateKey();
  Cipher c = Cipher.getInstance(ALGORITHM);
  c.init(Cipher.ENCRYPT_MODE, key);

  String valueToEnc = null;
  String eValue = value;
  for (int i = 0; i < ITERATIONS; i++) {
    valueToEnc = encryption_key + eValue;
    byte[] encValue = c.doFinal(valueToEnc.getBytes());
    eValue = new sun.misc.BASE64Encoder().encode(encValue);
  }
  return eValue;
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:30,代码来源:DefaultEncryptionServivceImpl.java

示例12: AESSensitivePropertyProvider

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
public AESSensitivePropertyProvider(String keyHex) throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException {
    byte[] key = validateKey(keyHex);

    try {
        Security.addProvider(new BouncyCastleProvider());
        cipher = Cipher.getInstance(ALGORITHM, PROVIDER);
        // Only store the key if the cipher was initialized successfully
        this.key = new SecretKeySpec(key, "AES");
    } catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException e) {
        logger.error("Encountered an error initializing the {}: {}", IMPLEMENTATION_NAME, e.getMessage());
        throw new SensitivePropertyProtectionException("Error initializing the protection cipher", e);
    }
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:14,代码来源:AESSensitivePropertyProvider.java

示例13: decrypt

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
private byte[] decrypt(byte[] cipherText, byte[] key, byte[] initialVector)
		throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
		InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
	Cipher cipher = Cipher.getInstance(cipherTransformation);
	SecretKeySpec secretKeySpecy = new SecretKeySpec(key, aesEncryptionAlgorithm);
	IvParameterSpec ivParameterSpec = new IvParameterSpec(initialVector);
	cipher.init(Cipher.DECRYPT_MODE, secretKeySpecy, ivParameterSpec);
	cipherText = cipher.doFinal(cipherText);
	return cipherText;
}
 
开发者ID:michaelnetter,项目名称:dracoon-dropzone,代码行数:11,代码来源:CryptoUtil.java

示例14: encrypt

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
public String encrypt(String plainText, String key) {
	String encodedString = "";

	try {
		byte[] plainTextbytes = plainText.getBytes(characterEncoding);
		byte[] keyBytes = getKeyBytes(KEY_PREFIX + "" + key);
		encodedString = Base64.getEncoder().encodeToString(encrypt(plainTextbytes, keyBytes, keyBytes));
	} catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException
			| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	return encodedString;

}
 
开发者ID:michaelnetter,项目名称:dracoon-dropzone,代码行数:17,代码来源:CryptoUtil.java

示例15: createCipher

import javax.crypto.NoSuchPaddingException; //导入依赖的package包/类
protected Cipher createCipher(int mode, String algorithm, String provider, Key key, AlgorithmParameters params)
throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException, InvalidKeyException, InvalidAlgorithmParameterException
{
    Cipher cipher = null;

    if (cipherProvider == null)
    {
        cipher = Cipher.getInstance(algorithm);
    }
    else
    {
        cipher = Cipher.getInstance(algorithm, provider);
    }
    cipher.init(mode, key, params);
    
    return cipher;
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:18,代码来源:DefaultEncryptor.java


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