Can't get it to work!!! Please help with IllegalBlockSizeException

I have tried several things, I have searched the forume many times ever
since yesterday, but I just can't figure this out. Here is my method to encrypt:
private void encryptPassword(String p)
try{
//generate key using DES algorithm
byte key[] = "ababcabc".getBytes();
SecretKeySpec secretKey = new SecretKeySpec(key,"DES");
//get cipher for DES algorithm
Cipher cipher = Cipher.getInstance ("DES");
cipher.init(Cipher.ENCRYPT_MODE,secretKey);
//encrypt password
//byte[] tmp = Base64.encode(p.getBytes());
byte[] encryptedPswd = cipher.doFinal(p.getBytes("UTF-8"));
//byte[] encryptedPswd = cipher.doFinal(tmp);
password = new String(encryptedPswd, "UTF-8");
catch(Exception e){
logger.error("ERROR: Unable to encrypt password "
                                   + "due to Exception: " + e);
And here is my method to decrypt:
private String decryptPassword()
try
{   //generate key using DES algorithm
byte key[] = "ababcabc".getBytes();
SecretKeySpec secretKey = new SecretKeySpec(key,"DES");
//get cipher for DES algorithm
Cipher cipher = Cipher.getInstance ("DES");
cipher.init(Cipher.DECRYPT_MODE,secretKey);
//byte[] cipherCode = Base64.decode(password.getBytes());
//byte[] decryptedPswd = cipher.doFinal(cipherCode);
byte[] decryptedPswd = cipher.doFinal(password.getBytes("UTF-8"));
return new String(decryptedPswd, "UTF-8");
catch(Exception e){
logger.error("ERROR: Unable to decrypt password "
                                   + "due to Exception: " + e);
return "";
As you can see, I have tried to use Base64 encoder, but that didn't work either. I got ArrayIndexOutOfBounds exception with that. I followed this thread to try that: http://forum.java.sun.com/thread.jsp?forum=9&thread=302490. I used to get BadPaddingException when I didn't use "UTF-8" encoding. But now I get IllegalBlockSizeException. Please let me know what I am doing wrong.
Thank you so much!
Malia

I found the answer to my question at this site: http://javaalmanac.com/egs/javax.crypto/DesString.html
The key is to use base64 encoding, but I didn't know that the class sun.misc.BASE64Encoder and sun.misc.BASE64Decoder comes with regular JDK. I searched for base64 encoders, but the implementation from Ostermiller didn't work for me. So, for those having the same problem, go to that site. Here is the snapshot:
public class DesEncrypter {
Cipher ecipher;
Cipher dcipher;
DesEncrypter(SecretKey key) {
try {
ecipher = Cipher.getInstance("DES");
dcipher = Cipher.getInstance("DES");
ecipher.init(Cipher.ENCRYPT_MODE, key);
dcipher.init(Cipher.DECRYPT_MODE, key);
} catch (javax.crypto.NoSuchPaddingException e) {
} catch (java.security.NoSuchAlgorithmException e) {
} catch (java.security.InvalidKeyException e) {
public String encrypt(String str) {
try {
// Encode the string into bytes using utf-8
byte[] utf8 = str.getBytes("UTF8");
// Encrypt
byte[] enc = ecipher.doFinal(utf8);
// Encode bytes to base64 to get a string
return new sun.misc.BASE64Encoder().encode(enc);
} catch (javax.crypto.BadPaddingException e) {
} catch (IllegalBlockSizeException e) {
} catch (UnsupportedEncodingException e) {
} catch (java.io.IOException e) {
return null;
public String decrypt(String str) {
try {
// Decode base64 to get bytes
byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
// Decrypt
byte[] utf8 = dcipher.doFinal(dec);
// Decode using utf-8
return new String(utf8, "UTF8");
} catch (javax.crypto.BadPaddingException e) {
} catch (IllegalBlockSizeException e) {
} catch (UnsupportedEncodingException e) {
} catch (java.io.IOException e) {
return null;
Here's an example that uses the class:
try {
// Generate a temporary key. In practice, you would save this key.
// See also e464 Encrypting with DES Using a Pass Phrase.
SecretKey key = KeyGenerator.getInstance("DES").generateKey();
// Create encrypter/decrypter class
DesEncrypter encrypter = new DesEncrypter(key);
// Encrypt
String encrypted = encrypter.encrypt("Don't tell anybody!");
// Decrypt
String decrypted = encrypter.decrypt(encrypted);
} catch (Exception e) {

Similar Messages

  • I just got my printer to day and can not get it to work please help p.s. email nsdolan@comcas

    THIS IS A HP DESKJET 3050A ALL-IN-ONE J611 SERIES

    Hi NEDJDOLAN4,
    What functionality is not working for your Deskjet 3050A:
    -Printing from the computer?
    -Printing from a mobile device?
    -Scanning to a device?
    -Copying by stand-alone?
    -Sending an ePrint job?
    If I have solved your issue, please feel free to provide kudos and make sure you mark this thread as solution provided!
    Although I work for HP, my posts and replies are my own opinion and not those of HP.

  • I just bought Quick time Pro and I can't get it to install. It shows a yellow box in my application folder, but I can't get it to work. Help!

    I just bought Quick time Pro and I can't get it to install. It shows a yellow box in my application folder, but I can't get it to work. Help!

    you launch QT then go to its REGISTRATION

  • I've accidentally closed my program sequence at the top. And now I can't get it back. Please help

    I've accidentally closed my program sequence at the top. And now I can't get it back. Please help. All my source, timeline, sequences are blank...

    Go to the Media Panel and double click on the sequence.

  • HT1245 Help me please..I lost all my contacts when i sync. it with google contacts ..they completely gone from iphone and my gmail account ..how can i get them back? please help

      Help me please..I lost all my contacts when i sync. it with google contacts ..they completely gone from iphone and my gmail account ..how can i get them back? please help

    Its a easy fix,it will take too much time to type out all of the steps,
    Check your email account. see if they are their, You can then import them on your DAV card, The best thing to is add them to icoud then they will be safe.
    Apple support can talk you through it.

  • Can't get iphoto to work after tampering with library in Finder

    I think I made a big mistake when I tampered with the iphoto library in Pictures in Finder.
    Now I can't get iphoto to work. All the pictures are gone in iphoto, the spaces are there but they are blank.
    When I open iphoto it goes into the mode (little spinning wheel appears) where I have to "force quit".
    Any supggestions on what I can do? Thanks.

    The list that shows is just data files and such.
    You can burn the entire iPhoto Library folder.
    You can burn each Year folder or any other variation.
    This is my workflow. The reason I do it the way I describe is because I want a backup of just the photos and video clips I take so I can copy them to a partition of my external drive and burn them to disc. On the other partition I backup my entire users folder
    When iPhoto 5 first came out I really think it was programmed to import the smaller 30 sec video clips that cameras were taking at the time. Since then, digital cameras, at least my Canon S2 can take clips as large as your memory card can hold. The first time I tried to download my images and movie clips with my new camera, iPhoto stalled at the movie clips. I wasn't going to take any chances messing up my iPhoto Library so I started using Image Capture to download all my images and Movie clips. I actually like doing it this way a lot better. My movie clips are downloaded into my Movies folder where I then put them in a dated folder.
    My photos are downloaded into my Pictures folder, where I then put them in a dated folder. I import the dated folder into iPhoto. I also keep all dated folders from photo downloads in the Pictures folder till I get enough Movie folders and Photo folders to fill a DVD. I burn them and then delete them from the hard drive.
    This way I have the photos in iPhoto and I also have just the photos backed up to DVD.
    The Movies I keep on the hard drive in their dated folders until I use all the clips for my iMovie projects for the Year. I then make sure they are all burned to DVD, then I delete those from my hard drive.
    Using Image Capture to download images and video clips:
    Open up Image Capture which is found in the Applications folder.
    When it is opened, go to Image Capture/Preferences
    Under the General button choose
    Camera: When a camera is connected, open Image Capture.
    The next time you connect your camera Image Capture will open.
    In the window that opens you will see an Options button. Click on that button to set your options.
    To find out more about Image Capture (it can do a lot more) Click on Help in the menu bar when Image Capture is open.
    iPhoto: How to Change the "Open Automatically" Preference
    If you find you can't change any of Image Captures preferences or can't access any drop down menus or they are greyed out, check to make sure Image Capture is loose in the Applications folder and not within a sub folder.
    Here is info on backing up your photos:
    Backing up your iPhoto Library
    1. Burn the iPhoto Library folder in the Finder to a CD or DVD
    This method will give you a burned iPhoto Library folder that can be copied back to your computer to replace a damaged library. You can also use this method to backup an old library when you want to create a new Library to use as your current library.
    insert a blank CD into your internal or external CD-RW drive and copy the iPhoto library to the CD icon on your desktop. When you drag the CD icon to the Trash/Eject button in the Dock, you are given the option to burn the CD. Click Burn and the CD is created. To burn a DVD backup of your digital images, use a DVD and a SuperDrive-equipped Mac
    The easiest way to burn an iPhoto Library folder in the Finder that is larger than 4.7 gig to fit on one DVD is to burn sections of the folder.
    Drag the iPhoto Library folder to the desktop
    Double click the folder to open it.
    Drag each Year folder to the desktop.
    You should be left with the iPhoto Library folder containing all the data files, and the Year folders.
    Combine whatever year folders that amount closest to a DVD burn size on one DVD. Make sure that you have burned all the Year folders, then the iPhoto Library folder with all the data files.
    If you ever need to use this backup, insert the DVDs into your computer and copy the folders to the desktop. Put all the Year folders back into the iPhoto Library folder. Then put the iPhoto Library folder back into the Pictures folder.
    You can also check out applications for disc spanning:
    Disc-spanning software
    DropDMG
    Toast
    Dragon Burn 4
    BackityMac
    Retrospect Express-comes with some external drives
    Retrospect for Macintosh Desktop Edition
    2. Copy the ENTIRE iPhoto Library to an external drive formated for a Mac. Do not use this as your only back up as the external can also go bad.
    3. Copy the ENTIRE iPhoto Library to your iPod in disk mode
    4.Creating your own CDs and DVDs for viewing in iPhoto
    This method is a great way to back up Albums of older photos or even your entire library if it is small enough to fit on a DVD. This method will give you a library that will mount within iPhoto in the source column to be viewed. To import any images from this library they need to be dragged into your library in the source column.
    If you just want to backup the images in your library:
    1) Within iPhoto select the images, albums or rolls you want to backup. Go to Share>Export and export them to a newly created folder on the desktop. Follow the directions in the next link.
    Creating a CD or DVD to be viewed in Windows or by a photo processing company
    1.. If you backed up the entire iPhoto Library by burning within iPhoto or burning the folder in the Finder, make sure the burned copy is a good working copy before you delete the iPhoto Library folder in the Finder. You delete the iPhoto Library in the finder by dragging it to the trash when iPhoto is closed. When you next launch iPhoto it will create a new empty library for you to start anew.
    2. If you burned just the images, be aware that that is all you are archiving. No metadata will travel with the images such as comments, keywords, etc.
    You can then delete those images within iPhoto by highlighting them and hitting the delete key, then empty iPhoto's trash. Do this often and in groups so iPhoto will not choke on too many images.

  • HT201209 I use a Gift card to buy a game and it doesn't work how can I get my money back please help

    I used a gift card to buy games and one of them doesn't  work how can I get my money back

    If the game doesn't work (and you've tried deleting it and re-downloading it via the Purchased tab in the App Store app and you've also tried contacting the app's developer) then try the 'report a problem' page to contact iTunes Support : http://reportaproblem.apple.com
    If the 'report a problem' link doesn't work then you can try contacting iTunes support via this page : http://www.apple.com/support/itunes/contact/- click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • I recently purchased U2 Any DVD Ripper on Mac App Store and can not get it to work!  Help!!

    I can not find any documentation on how to use this software.  I can not figure out how to get it to copy a DVD to Mp4 format on my media hard drive, allowing me to watch the video on my apple tv.  Please help or direct me to get a refund for this $14.99 purchase. 

    Did you reset your PRAM?
    command-option- p-r
    Hold down all four keys as the mac starts up and wait for the chimes to ring twice. Then let the machine start up as usual.
    If it works be sure to check your date and time settings (the system will tell you)
    You can also start up from your system disk holding down the c key as it starts-- go past the language screen and open disk utilities from the menu bar run disk repair and then repair permissions. Set your startup disk to your new drive.
    Hopefully that will take care of the problem.

  • I have a compilation problem with my mini iPod that is preventing my volume from increasing. I can't get the compilation code, please help me

    MY mini iPod version number1.1.3 pc robs iPod ,4GB is having volume limit problem ,the volume is very low compare to how it was playing before I mistakenly touch the combination code. I have forgotten the combination code, please help me out.. I have tried to reset settings but it wouldn't work.

    i can get the combination code please

  • Having trouble changing master password as i have forgotten it and can not get it to reset please help

    I have tried to remember what the first pass word was and can not get it done. i can not send out emails on both of my email accounts [email protected] or [email protected] as both request password. when i have tried to reset master password it will not except any thing that i am doing. i need to send out emails for my work and having trouble doing the change. Please help

    The master password protects saved passwords in Thunderbird and has nothing to do with connecting to your providers server. You need to work with your email provider if you have forgotten your email password. Go to their email help site and look for a link to reset your password.
    If you are truly working with a forgotten master password this article tells you how to remove it.
    https://support.mozilla.org/en-US/kb/master-password

  • Have converted videos to MP4 - Can't get them to iPod - Please help!

    I know there are threads on this subject already - why is it soooo **** hard to get a personal (non iTunes video) onto a new iPod?
    I have converted my videos to MP4 - I have them in the Videos main folder - when I update....nothing happens. Why??
    Can someone please help me with this... Why would Apple make this so hard?
    Thx

    So can you see the thumbnails in the video folder? If so, try dragging the thumbnail onto the iPod icon and see if it works that way.

  • Can't get battery to charge - please help before I pull my hair out

    My daughter and I both have the Curve 8530, first, her battery didn't seem to hold a charge very long, then her charging port stopped working.  So we started swapping the batteries.  When hers was low, I would give her mine with more charge and charge up the other one, using it until the first one needed a charge.  That started getting more and more frequent, now, all of the sudden I can't get either one to charge in my phone.  Figured out that hers doesn't charge because it is broken.  We can see a piece of metal that should be on the little tab in the port, laying at the bottom of the port.  Mine is a little loose after 2 years, so I sometimes have to wiggle the connection or make sure I set it down and don't move it when it is charging.  However, this is making me crazy.  It was plugged into my computer usb to charge all night and was completely dead this morning.  Which, is not a big suprise as the usb port on my computer doesn't always like to charge the BB.  Gives me an error saying not enough power.  So I plugged in the wall charger and let it sit.  It gets far enough that it will start the OS, but then sat there for hours and never changed from red and didn't get even 1 bar of charge.  Usually it only take a short time.  I read another post about an internal circular battery under the sticker with all the identification numbers on it, but I don't see any battery resembling that and am not comfortable taking my BB apart like that.  So any suggestions as to what the problem might be?  Or how to fix it?  My daughter's, though she doesn't think so, is not near as important as having at least one battery for mine due to work, etc.  Thanks for reading and any help.
    Jenn

    I would suggest trashing the .itl and .xml files to make sure you start clean (quit iTunes before you trash the files, of course). Then use the Add Folder To Library command and select your iTunes Music folder. That should get everything back into iTunes, though you won't get any playlists back unless you made a backup of them.

  • My friend wanted to get some of the music off my itunes. when syncing it needed to udate her phone which it did - now all her photos are gone. and the last back up was from when she used my itunes 6  ago. How can we get back her photos :(Please help

    My friend wanted to get some music off my itunes - when syncing it it said she had to update her phone software first - which it did. Now all her photos are gone. When we tried to restore the last back up - the only one was from when she used my itunes 6 months ago which was from her old iphone. So now it has put all her photos from her old phone onto her new iphone and deleted all the new ones. We cannot find her new photos. Please help and there was 100 new pics. Is there any way we can get them back. I already have the program Asoftech - but it doesnt seem to register the iphone only C and D drive. Please help!

    bechosken wrote:
    My friend wanted to get some music off my itunes
    This is called "stealing". You do not have the legal right to give her the music you have in your iTunes library unless you are the copyright holder.
    when syncing it it said she had to update her phone software first
    That's not quite what it said.  Someone should have paid more attention to the great big warning about the possibility of losing data if the phone wasn't backed up.
    We cannot find her new photos. Please help and there was 100 new pics. Is there any way we can get them back. I already have the program Asoftech - but it doesnt seem to register the iphone only C and D drive. Please help!
    It restored the backup that was made on your computer 6 months ago, which did not contain those photos. You're wasting your time trying to find them on the phone. They don't exist.
    Hopefully, your friend syncs her phone to her own computer on a regular basis. She needs to plug her phone into her computer and restore it from her last backup. That will restore it to the state it was in when the backup was made.
    She also needs to get in the habit of extracting the photos on a regular basis, like she would from any other digital camera.

  • Cannot Get Connection to Work, Please Help!

    I just signed up and got the 7500 wireless gateway, set up all the wiring as illustrated (double checked 4 times to be sure).  I have the E4 line going into my computer's jack and its supposed to provide wireless service anyway.  My computer says it recognizes having connectivity, but when I run the Verizon setup CD, it keeps saying it can't connect during the test.  I can't get anywhere on the web with any browser, but I can't see what is wrong.
    Before anyone asks, my activation date was last Tuesday.  I could really use some help!

    Since some how and way, you can access the net - with the computer that you are posting from.
    #1 Go to
    https://www22.verizon.com/foryourhome/eRepairNet/DSLRepairANR/common/DSL_Repair.aspx
    And check the order status.
    #2 Also see as need https://www22.verizon.com/foryourhome/eRepairNet/DSLRepairANR/Common/SupportDetails.aspx?case=c18247
    ^^
    If you are the original poster (OP) and your issue is solved, please remember to click the "Solution?" button so that others can more easily find it. If anyone has been helpful to you, please show your appreciation by clicking the "Kudos" button.

  • Palm tx  can't get it to sync Please Help

    I just got a palm tx yesterday and can not get it to sync with my new Intel IMAC I am a new mac user only 1 week.. Please If anyone can help me out Thanks Herb

    Make sure it came with the latest Palm Desktop for OS X. It should be 4.2.1 Revision D. If it didn't then download it from Palm's site.
    Since Palm was a bit lackluster in their support for OS X, I switched to Mark/Space's Missing Sync for Palm OS. It is smooth as silk with OS X and does more than the Palm sync software.
    http://www.markspace.com/

  • I reseted my MacBook Air, and now I don't have my iPhoto or Microsoft Office anymore. how can i get them back ? please help me..

    I reseted my MacBook Air, and now I don't have my iphoto and microsoft office anymore, please help me..how can i get them back?

    Thank you for your question,
         If you have the installation disc for iLife and MS Office, then you can install it from there. With iPhoto, if you downloaded it from the Mac App Store, you can redownlad it fron the "Purchases" tab.

Maybe you are looking for

  • Calculation of Perk value for Housing Deposits

    Our Company is offering Security Deposits for housing (mainly in case of Mumbai Employees)  as Interest free loans and getting it recovered in 36 instalments. The perk value as per IT rules shall be added in the annual gross salary of the employee.St

  • VBA Photoshop reference

    Any ideas on why Photoshop doesn't show up in VBA / Tools / Reference? I want to program in VBA using excel and effecting photoshop, but can not find the reference library for photoshop Using CS2 and Windows for Mac...macbook pro Thanks

  • Rank Function taking a long time to execute in SAP HANA

    Hi All, I have a couple of reports with rank function which is timing out/ or taking a really long time to execute, Is there any way to get the result in less time when rank functions are involved? the following is a sample of how the Query looks, SQ

  • I have credits - why can't I buy songs?

    I have some money on my itunes account - it was originally from a giftcard, but when I try and purchase songs it won't let me!  It keeps reverting me to the billing information.  Help please!

  • Photos ::  adding to existing

    How may I add new photos to my iPad without iTunes in the sync process deleting the photoa already in the iPad?