Encrypt And Decrypt Using Blowfish In Java

Java Cryptography classes offer a variety of ways for you to encrypt and decrypt. One of them is using Blowfish. The methods below encrypt and decrypt Strings using a String key as its secret key.

Related Posts Plugin for WordPress, Blogger...

45 comments

  1. Dear mr/mrs

    Please help me to solve my duty about blowfish,, I really need help..please…
    thank you very much…

  2. I got error “Unable to encrypt the object: Cipher Blowfish implementation not found
    “.

    Can you explain me how to fix it?

    Thank you so much in advance..

  3. I got error “Unable to encrypt the object: Cipher Blowfish implementation not found
    “.

    Can you explain me how to fix it?

    Thank you so much in advance..

    Here is my code:

    SecretKey result = null;
    byte key[] = keyString.getBytes();
    try {
    DESKeySpec desKeySpec = new DESKeySpec(key);
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(“Blowfish”);
    result = keyFactory.generateSecret(desKeySpec);
    } catch(Exception e) {
    e.printStackTrace();
    }

    SealedObject sealedObject = null;
    Cipher desCipher = Cipher.getInstance(“Blowfish”);
    desCipher.init(Cipher.ENCRYPT_MODE, result);
    sealedObject = new SealedObject(theQueue, desCipher);
    oos.writeObject(sealedObject);

  4. i am newer in java so i don’t know about jdk.

    But if i use “DES” algorithm instead of “Blowfish” then it works fine.

  5. Still i got the “Cipher Blowfish implementation not found” error on “SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(“Blowfish”);” line in my emulator.

  6. Error seems that i have to add the “Blowfish” library.

    If yes then i have already imported my “Blowfish” class but it does not solve the problem.

  7. but script above only encrypt and decrypt. and I need encrypt-decrypt for communication by SMS with blowfish algorithm in J2ME. please help me. I’m really need for my study. But I’m not good on programmer.
    Big hope you can help me.

    Thank you

  8. But I dont understand how SMS source code, and I dont know how to insert above program in SMS sorce code.
    Sorry if it’s complicated.
    But I really need it.
    Please
    Thank you

  9. This is great! I am glad you posted this. This works fine from the command line, but when I use a GUI it doesn’t seem to work.

    I use jTextArea1.getText() as the “to_encrypt” or “to_decrypt” and jPasswordField1.getText()as strkey.

    It works fine on encryption but returns null on decryption.

    Any ideas on this?

  10. @geeth: dude. please use an IDE so it will import the packages for you. i dont have the code with me anymore

    or, just google those classes.

  11. can u plz tell me how to execute that above code in the project. we are preparing for mini project but we dont know how to exicute the code so plz help me sir….

  12. String key = “12”;
    String encrypt = “We are the champions of world”;
    System.out.println(encryptBlowfish(encrypt, key));

    The result is эЉiмR«|.к¤ЃtћОХЌxшИ©[An
    How to fix it to the normal view?
    Thanks.

  13. I am able to encrypt but decrypt string shows as null

    String toencrpt=AccreditEncryption.encryptBlowfish(“zahid asnari”, “1234567890”);
    String todecrpt=AccreditEncryption.decryptBlowfish(toencrpt, “1234567890”);

    System.out.println(“encrypted string =”+toencrpt);
    System.out.println(“decrypted string =”+todecrpt);

    Result:

    encrypted string =��$�F�����(7�
    decrypted string =null

  14. I am able to encrypt but decrypt string shows as null
    String toencrpt=AccreditEncryption.encryptBlowfish(“zahid asnari”, “1234567890″);
    String todecrpt=AccreditEncryption.decryptBlowfish(toencrpt, “1234567890″);
    System.out.println(“encrypted string =”+toencrpt);
    System.out.println(“decrypted string =”+todecrpt);

    Result:
    encrypted string =��$�F�����(7�
    decrypted string =null

    Error on catalina log

    javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher

  15. Hi,

    What kind of blowfish is this?

    Your code is working fine but I’m sending the string to an iPhone and I’m unable to decrypt it overthere, i see there’s different blowfish like ECB, and others.

    How can I decrypt this string on other programming languages?

Leave a Reply

Your email address will not be published. Required fields are marked *