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 8576793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:00:25+00:00 2026-06-11T20:00:25+00:00

I have a pre-written code which is used to cipher the given plain text

  • 0

I have a pre-written code which is used to cipher the given plain text or vice-versa .

The class has 3 methods, where in 2 methods can be used for encrypting and decrypting respectively.

public class SqlCipherUtil {

    private Cipher ecipher;
    private Cipher dcipher;

    public String encryptString(String pStrPlainText) {

        try {
            generateKey();
            byte[] utf8 = pStrPlainText.getBytes("UTF8");
            byte[] enc = this.ecipher.doFinal(utf8);
            return new BASE64Encoder().encode(enc);

        } catch (Exception e) {
            e.printStackTrace();
        } 

        return null;
    }

    public String decryptString(String pStrCipherText){

        try {
            generateKey();
            byte[] dec = new BASE64Decoder().decodeBuffer(pStrCipherText);
            byte[] utf8 = this.dcipher.doFinal(dec);
            return new String(utf8, "UTF8");

        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * This method is used to generate the encrypted key.
     */
    private void generateKey() {

        try {
            byte[] decodedStr = new BASE64Decoder().decodeBuffer("rA/LUdBA/hA=");
            SecretKey key = new SecretKeySpec(decodedStr, "DES");
            this.ecipher = Cipher.getInstance("DES");
            this.dcipher = Cipher.getInstance("DES");
            this.ecipher.init(1, key);
            this.dcipher.init(2, key);

        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

The key present in the class cannot be changed to any other key
in line byte[] decodedStr = new BASE64Decoder().decodeBuffer("rA/LUdBA/hA=");,
and it is giving an exception.

java.security.InvalidKeyException: Invalid key length: 9 bytes
    at com.sun.crypto.provider.DESCipher.engineGetKeySize(DashoA13*..)
    at javax.crypto.Cipher.b(DashoA13*..)
    at javax.crypto.Cipher.a(DashoA13*..)
    at javax.crypto.Cipher.a(DashoA13*..)
    at javax.crypto.Cipher.a(DashoA13*..)
    at javax.crypto.Cipher.init(DashoA13*..)
    at javax.crypto.Cipher.init(DashoA13*..)

I tried out the below code, and I am getting exactly 8 bytes in the array.

    public static void main(String[] args) throws IOException {
        byte[] decodedStr = new BASE64Decoder().decodeBuffer("rA/LUdBA/hA=");

        for(byte b : decodedStr){
            System.out.print(b);
            System.out.print(" ");
        }
    }

}

Any other combination of the key will make the byte array size more than 8 or less than 7.

What is the concept behind getting the byte array size 8 ?

What should be done to use custom key combination or our custom generated keys ?

Please answer Both the questions.

  • 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-06-11T20:00:26+00:00Added an answer on June 11, 2026 at 8:00 pm

    if your target is encode and decode the string, Use Base64.

        public class PasswordCodecHandler {
            Base64 codec = null;
    
            public PasswordCodecHandler() {
                codec = new Base64();
            }
    
            public String encode(String password) {
                byte[] temp;
                String encodedPassword = null;
                temp = codec.encode(password.getBytes());
                encodedPassword = new String(temp);
                return encodedPassword;
            }
    
            public String decode(byte[] encodedPassword) {
                byte[] temp;
                String decodedPassword;
                temp = codec.decode(encodedPassword);
                decodedPassword = new String(temp);
                return decodedPassword;
            }
    
            public static void main(String[] args) {
                PasswordCodecHandler passwordCodecHandler = new PasswordCodecHandler();
                String s1 = passwordCodecHandler.encode("password");
                System.out.println(s1);
    
                String s2 = passwordCodecHandler.encode("admin");
                System.out.println(s2);
    
                String s3 = passwordCodecHandler.encode("administrator");
                System.out.println(s3);
    
                String s4 = passwordCodecHandler.encode("123456");
                System.out.println(s4);
    
            }
        }
    

    For other data type : it can be java.lang.OutOfMemoryError based on the your memory allocation size

        /* Download apache common-io.xxx. jar*/
    
        public class CodecHandler {
            Base64 codec = null;
    
            public CodecHandler() {
                codec = new Base64();
            }
    
            public byte[] encode(byte[] decoded) {
                return codec.encode(decoded);
            }
    
            public byte[] decode(byte[] encoded) {
                return codec.decode(encoded);
            }
    
            public static void main(String[] args) throws IOException {
                File file = new File("D:/Test.mp4");
                byte[] fileByteArray = FileUtils.readFileToByteArray(file);
                CodecHandler codecHandler = new CodecHandler();
                byte[] encoded = codecHandler.encode(fileByteArray);
                System.out.println("Byte Size : " + encoded.length);
                byte[] decode = codecHandler.decode(encoded);
                FileUtils.writeByteArrayToFile(new File("C:/Test.mp4"), decode);
    
    
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using some pre-written JavaScript from polldaddy. They have a JavaScript option which,
I have written some physics simulation code in C++ and parsing the input text
I have the following code, which is written for the Titanium framework for mobile
I have a pre-written code in Php where JavaScript function is called echo <a
I have a bunch of code that's already written which currently relies on images
I have a web application written in pure JavaScript (no pre-generated HTML except for
I have a couple of pre-existing applications which I need to run in one
I have a pre-existing c++ object model which represents the business layer tier of
Is there a library in Java, that allows adding pre-written VBA code into a
I have the following code written, <?php require_once products.php; $test = new Products; $array

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.