java.lang.Object
java.lang.Throwable
java.lang.Exception
java.security.GeneralSecurityException
javax.crypto.BadPaddingException
- All Implemented Interfaces:
- Serializable
- See Also:
- Top Examples, Source Code
public BadPaddingException()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[371]Decrypting bytes in DES/ECB/PKCS5Padding mode
By manoj { at } manojnet { dot } com on 2003/08/26 01:29:38 Rate
try {
KeyGenerator keygen = KeyGenerator.getInstance ( "DES" ) ;
SecretKey desKey = keygen.generateKey ( ) ;
Cipher desCipher = Cipher.getInstance ( "DES/ECB/PKCS5Padding"
) ;
desCipher.init ( Cipher.DECRYPT_MODE, desKey ) ;
byte [ ] tempByte = ( iaMessage.basicMessage.basicMessage2 ) .get
Bytes ( ) ;
System.out.println ( "length before decription: = " + tempByte
.length ) ;
byte [ ] ediByte = desCipher.doFinal ( tempByte,0, tempByte.leng
th ) ;
System.out.println ( "tempByte [ ] length after decription = " +
tempByte.length ) ;
ediString = new String ( ediByte ) ;
} catch ( java.security.NoSuchAlgorithmException e ) {
System.out.println ( "NoSuchAlgorithmException : " + e ) ;
} catch ( java.security.InvalidKeyException e ) {
System.out.println ( "InvalidKeyException : " + e ) ;
} catch ( javax.crypto.IllegalBlockSizeException e ) {
System.out.println ( "IllegalBlockSizeException : " + e ) ;
} catch ( javax.crypto.NoSuchPaddingException e ) {
System.out.println ( "NoSuchPaddingException : " + e ) ;
} catch ( javax.crypto.BadPaddingException e ) {
System.out.println ( "BadPaddingException : " + e ) ;
}
public BadPaddingException(String msg)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1567]Properly use RSA encryption
By Anonymous on 2005/10/08 18:14:18 Rate
Cipher.getInstance ( "RSA/ECB/NoPadding" ) ;
it works sometimes, but sometimes it throws this exception :
javax.crypto.BadPaddingException: Message is larger than Modulus.
It is common parlance to describe the modulus N as being "k bits" in length ( 2048 in your example ) , but this just means that 2^ ( k-1 ) < N < 2^k. To properly use RSA, you must ensure that your message is not merely limited to k bits, but more specifically that it is less than N. This condition is necessary to ensure unique decryption. This is just one of the issues that is solved by using PKCS1 padding ( the default ) instead of NoPadding. The downside is that your transmission efficiency is reduced because, as the previous responder stated, you can only encrypt 2048-88 bits for every 2048 bits you send.