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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:15:39+00:00 2026-05-25T18:15:39+00:00

I need to protect a sequence of bytes with cryptography and I will need

  • 0

I need to protect a sequence of bytes with cryptography and I will need to recover the data later.
I want to use a key/password to encrypt and decrypt the data.

I am using Java. How do I encrypt and decrypt a string with a key or password in Java?

Thanks.

Edit: The method cannot be slow.

  • 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-25T18:15:40+00:00Added an answer on May 25, 2026 at 6:15 pm

    I hope this helps you get a general idea. This one is Symmetric cryptography.

    import java.security.*;
    import java.security.cert.*;
    import java.security.interfaces.*;
    import java.security.spec.*;
    import javax.crypto.*;
    import javax.crypto.interfaces.*;
    import javax.crypto.spec.*;
    import java.io.*;
    /**
     *  AES
     */
    public class SymmetricAES {
    
        public SymmetricAES() {
        }
    
        public static void main(String args[]){
            BufferedReader ch = new BufferedReader(new InputStreamReader(System.in));
            char[] toCode;
            byte[] toCode2;
            byte[] Coded;
            char[] Coded2;
            byte[] decoded;
            char[] deco2;
    
            try{
                System.out.print("Text to Encrypt : ");
                String toMake = ch.readLine();
    
                /** Arxikopoihsh antikeimenou KeyGenerator gia AES
                 *  kai dhmhourgia Kleidioy */
                KeyGenerator keyGen = KeyGenerator.getInstance("AES");
                SecretKey aesKey = keyGen.generateKey();
    
                /* Arxikopoihsh aesCipher gia AES */
                Cipher aesCipher = Cipher.getInstance("AES");
    
                /* Orismos aesCipher se ENCRYPT_MODE me to aesKey */
                aesCipher.init(Cipher.ENCRYPT_MODE, aesKey);
                System.out.println("The Key : " + aesKey.getEncoded());
    
                /* Metatroph antikeimenou String se pinaka Char
                 * kai o ka8e xarakthras gineta Cast se Byte kai eisagwgh
                 * se pinaka Byte isou mege8ous me ton prwto pinaka */
                toCode = toMake.toCharArray();
                toCode2 = new byte[toCode.length];
                Coded = new byte[toCode.length];
                for(int i=0;i<toCode.length;i++)
                    toCode2[i] = (byte)toCode[i];
    
                /* Teliko stadio Kryptografhshs */
                Coded = aesCipher.doFinal(toCode2);
    
                /* byte[] --> char[] kai ektypwsh*/
                Coded2 = new char[Coded.length];
                for(int i=0;i<Coded.length;i++)
                    Coded2[i] = (char)Coded[i];
                System.out.println("Test Encrypt: " + new String(Coded2));
    
    
                Cipher aesCipher2 = Cipher.getInstance("AES");
    
                /* Orismos aesCipher2 se DECRYPT_MODE me to aesKey */
                aesCipher2.init(Cipher.DECRYPT_MODE, aesKey);
    
                decoded = aesCipher2.doFinal(Coded);
    
                /* byte[] --> char[] kai ektypwsh*/
                deco2 = new char[decoded.length];
                for(int i=0;i<decoded.length;i++)
                    deco2[i] = (char)decoded[i];
                System.out.println("Test Decrypt: " + new String(deco2));
            }
            catch(Exception e){
                System.out.println(e);
            }   
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am generating a reports using SQL Reporting services 2005. I need to protect
to my project i need document editor for many types of documents(tabular data, invoices,
In my project I need to create a business object validation layer that will
In my project I need to use third party code, stored in several Git
I need to create a heads or tails project where the computer will guess
I need to run two programs in sequence as part of a custom builder.
I have a need to assign the next sequence number for a Project according
I'm building a command extension for the UML Sequence Diagram in VS2010, and need
My current iPad project-in-progress has the need for a sequence of events; It roughly
I need to protect my WCF web services and was thinking what is the

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.