本文整理匯總了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;
}
示例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;
}
示例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;
}
}
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}
}
示例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);
}
}
示例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;
}
示例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());
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}