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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:10:08+00:00 2026-06-08T18:10:08+00:00

I’m making an app that encrypts some files. I want to use gnu’s cryptix

  • 0

I’m making an app that encrypts some files. I want to use gnu’s cryptix library. It says it is no longer developed since 2005, but I guess it has everything I need… should I use something else?

And I have a question about encrypting a single file. Right now I do it with a loop like this:

for(int i=0; i+block_size < bdata.length; i += block_size)
    cipher.encryptBlock(bdata, i, cdata, i);

So my question is how to encrypt the last block that may not have the same size as the block_size. I was thinking maybe a should add some extra data to the last block, but than I don’t know how to decrypt that…

  • 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-08T18:10:09+00:00Added an answer on June 8, 2026 at 6:10 pm

    I would strongly suggest using AES encryption and it too comes with the JAVA SDK. Have a look at: Using AES with Java Technology which will give you some great example. To read up more on AES see: Advanced Encryption Standard – Wikipedia.

    Never use your own encryption scheme or an older form of an encryption scheme. AES has been tried and tested by people with far greater knowledge in that field then us, so you know it will work. Where as with your own or an old encryption scheme we might miss a fatal loop hole that will leave our data open to attacks.

    See this question here to see the difference in the encryption schemes: Comparison of DES, Triple DES, AES, blowfish encryption for data

    Addendum:

    AES in java will work flawlessly for 192 and 256bit keys but you will have to install the newer JCE Policy Files. See here and here. You should also place the files in your JDK or else it wont work when executed from your IDE.

    Note: Make sure you download the correct JCE policy files, depending on your Java version i.e 1.4, 1.5 1.6 or 7.

    However if you use 128bit keys no need to install the newer JCE files.

    Here is a template of some secure AES usage in java it use CBC/AES/PKCS5Padding and a random IV using RandomSecure.

    Note you need both the key and IV for decrypting:

    import java.io.UnsupportedEncodingException;
    import java.security.InvalidAlgorithmParameterException;
    import java.security.InvalidKeyException;
    import java.security.NoSuchAlgorithmException;
    import java.security.SecureRandom;
    import javax.crypto.*;
    import javax.crypto.spec.IvParameterSpec;
    import javax.crypto.spec.SecretKeySpec;
    
    /**
     * This program generates a AES key, retrieves its raw bytes, and then
     * reinstantiates a AES key from the key bytes. The reinstantiated key is used
     * to initialize a AES cipher for encryption and decryption.
     */
    public class AES {
    
        /**
         * Encrypt a sample message using AES in CBC mode with a random IV genrated
         * using SecyreRandom.
         *
         */
        public static void main(String[] args) {
            try {
                String message = "This string contains a secret message.";
                System.out.println("Plaintext: " + message + "\n");
    
                // generate a key
                KeyGenerator keygen = KeyGenerator.getInstance("AES");
                keygen.init(128);  // To use 256 bit keys, you need the "unlimited strength" encryption policy files from Sun.
                byte[] key = keygen.generateKey().getEncoded();
                SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
    
                // build the initialization vector (randomly).
                SecureRandom random = new SecureRandom();
                byte iv[] = new byte[16];//generate random 16 byte IV AES is always 16bytes
                random.nextBytes(iv);
                IvParameterSpec ivspec = new IvParameterSpec(iv);
    
                // initialize the cipher for encrypt mode
                Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
                cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivspec);
    
                System.out.println("Key: " + new String(key, "utf-8") + " This is important when decrypting");
                System.out.println("IV: " + new String(iv, "utf-8") + " This is important when decrypting");
                System.out.println();
    
                // encrypt the message
                byte[] encrypted = cipher.doFinal(message.getBytes());
                System.out.println("Ciphertext: " + asHex(encrypted) + "\n");
    
                // reinitialize the cipher for decryption
                cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivspec);
    
                // decrypt the message
                byte[] decrypted = cipher.doFinal(encrypted);
                System.out.println("Plaintext: " + new String(decrypted) + "\n");
            } catch (IllegalBlockSizeException | BadPaddingException | UnsupportedEncodingException | InvalidKeyException | InvalidAlgorithmParameterException | NoSuchPaddingException | NoSuchAlgorithmException ex) {
                ex.printStackTrace();
            }
        }
    
        /**
         * Turns array of bytes into string
         *
         * @param buf   Array of bytes to convert to hex string
         * @return  Generated hex string
         */
        public static String asHex(byte buf[]) {
            StringBuilder strbuf = new StringBuilder(buf.length * 2);
            int i;
            for (i = 0; i < buf.length; i++) {
                if (((int) buf[i] & 0xff) < 0x10) {
                    strbuf.append("0");
                }
                strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
            }
            return strbuf.toString();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.