Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7625987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:15:55+00:00 2026-05-31T05:15:55+00:00

I have some code that is working correctly in Java but when I try

  • 0

I have some code that is working correctly in Java but when I try to use it in Android it is having problems.

I am attempting to encrypt an SMS text message with the Blowfish algorithm.

The problem with this code (on android) is that it will not accept the byte[] and will not decrypt the message.

SENDING THE SMS

     sMessage = "hello this is a message"

     byte[] byteArray = EncryptBlowfish(sMessage);  
       //Convert the byte[] into a String which can be sent over SMS
      StringBuffer strb = new StringBuffer();

      for( int x = 0; x<byteArray.length; x++){
      strb.append(byteArray[x]).append(",");
      }//for loop

      sMessage = strb.toString();

(sMessage is then sent via SMS)

RECIVING THE SMS

         //Convert the String back to a byte[] which can be decrypted
        String[] strArray = sMessage.split(",");
        byte[] byteArray = new byte[strArray.length];
        int hold;

        for (int x = 0; x < strArray.length; x++) {
        hold = Integer.parseInt(strArray[x]);
        byteArray[x] = (byte) hold;
    }//for loop

        sMessage = DecryptBlowfish(byteArray);

Encryption Method

    public static byte[] EncryptBlowfish(String msg){

    byte[] encrypted =null;

    try {


    Cipher cipher = Cipher.getInstance("Blowfish");

    cipher.init(Cipher.ENCRYPT_MODE, secretkey);

    encrypted = cipher.doFinal(msg.getBytes());

    } catch (){ //NoSuchAlgorithmException, NoSuchPaddingException..etc
   }  

    return encrypted;
}

Decryption Method

        public static String DecryptBlowfish(byte[] msg){
      byte[] decrypted =null;
      try {


       Cipher cipher = Cipher.getInstance("Blowfish");

          cipher.init(Cipher.DECRYPT_MODE, secretkey);


     decrypted = cipher.doFinal(msg);

        } catch (){ //NoSuchAlgorithmException, NoSuchPaddingException..etc
     }  

    return decrypted;
}

The message is being encrypted, this creates a byte[], I have then converted the byte[] to a string, the string’s output will look something like this…

46,77,52,11,-108,91,-106,88,-81,-43,14,111,-118,-128,-92,-50,69,-44,100,-94,71,92,-49,116,

this output is then sent over SMS. The string is then convert back into a byte[]
but this byte array is not decrypting.

Questions:

  1. Why would this code work in a Java app, but not Android?
  2. Is there a way of making this work in Android?
  3. Is there a better method of converting the byte[] to a String and back.

(Please comment if anymore information is require, Thanks)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:15:56+00:00Added an answer on May 31, 2026 at 5:15 am

    I think the answer involves what the default character encoding is on Android vs standard Java. What happens if you specify the character encoding using msg.getBytes(Charset c), and for decoding new String(byte [], Charset c).

    Example:

    // String => byte []
    byte[] bytes = message.getBytes(Charset.forName("ISO-8859-1"));
    
    // byte [] => String 
    String foo = new String(bytes, Charset.forName("ISO-8859-1"));
    

    You can find what character sets are available from:

    for (String c : Charset.availableCharsets().keySet()) {
        System.out.println(c);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code I am working on that worked just fine until I
I have to modify some code in a application I am working on that
I have been working on some legacy C++ code that uses variable length structures
I have some really complicated legacy code I've been working on that crashes when
I'm currently working on some concurrent code that would appear to have a few
I'm currently working on a plug-in for Eclipse that translates some custom Java code
I tried to convert some C code to Java, but it is working slightly
I am currently working on some older java code that was developed without App
I have some code that gives a user id to a utility that then
I have some code that uses the shared gateway pattern to implement an inversion

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.