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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:51:56+00:00 2026-06-03T20:51:56+00:00

This is the current code im using for the encrypting and decrypting process also

  • 0

This is the current code im using for the encrypting and decrypting process also its works how it should be, except the time for encrypting and decrypting is way to long.

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;

public class EncryptAndDecrypt{

   public static void main(String[] args) {
    try {
        String key = "myencryptedpass123";

        FileInputStream fis = new FileInputStream("File_to_encrypt.mp4");
        FileOutputStream fos = new FileOutputStream("Encrypted_file.mp4");
        encrypt(key, fis, fos);

        FileInputStream fis2 = new FileInputStream("Encrypted_file.mp4");
        FileOutputStream fos2 = new FileOutputStream("File_to_decrypt.mp4");
        decrypt(key, fis2, fos2);
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

public static void encrypt(String key, InputStream is, OutputStream os) throws Throwable {
    encryptOrDecrypt(key, Cipher.ENCRYPT_MODE, is, os);
}

public static void decrypt(String key, InputStream is, OutputStream os) throws Throwable {
    encryptOrDecrypt(key, Cipher.DECRYPT_MODE, is, os);
}

public static void encryptOrDecrypt(String key, int mode, InputStream is, OutputStream os) throws Throwable {

    DESKeySpec dks = new DESKeySpec(key.getBytes());
    SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
    SecretKey desKey = skf.generateSecret(dks);
    Cipher cipher = Cipher.getInstance("DES"); 

    if (mode == Cipher.ENCRYPT_MODE) {
        cipher.init(Cipher.ENCRYPT_MODE, desKey);
        CipherInputStream cis = new CipherInputStream(is, cipher);
        doCopy(cis, os);
    } else if (mode == Cipher.DECRYPT_MODE) {
        cipher.init(Cipher.DECRYPT_MODE, desKey);
        CipherOutputStream cos = new CipherOutputStream(os, cipher);
        doCopy(is, cos);
    }
}

public static void doCopy(InputStream is, OutputStream os) throws IOException {
    byte[] bytes = new byte[64];
    int numBytes;
    while ((numBytes = is.read(bytes)) != -1) {
        os.write(bytes, 0, numBytes);
    }
    os.flush();
    os.close();
    is.close();
}

}

Now im hoping for a better solution…

  • 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-03T20:51:57+00:00Added an answer on June 3, 2026 at 8:51 pm

    Definitely use a bigger buffer, but encryption is mostly CPU-bound, so it is unlikely to get much faster. Additionally

    • if you ‘don’t bother about the security flaws’, it is better to give up on encryption altogether
    • you are using DES, don’t
    • you are using a human-readable string as a key — don’t
    • that code might no work once you are doing encryption and decryption with separate instance of Cipher
    • if you are using defaults, you are setting up yourself for trouble. Use something like Cipher.getInstance("AES/CBC/PKCS5Padding")
    • why are you testing on desktop if you want this to work on Android?

    And yes, if you include the key with the app, your ‘DRM’ is not of much use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my current code: public void WriteXml(System.Xml.XmlWriter writer) { CloseConnection(); using (Stream source
This is my current code: #include <list> #include <string> using std::string; using std::list; int
In my current code, I am using this code for files which have delimiter
I am having a bit of difficulty with this current code I have set
As a beginner in Ocaml, I have this current working code: ... let ch_in
if (webBrowser1.Url.AbsoluteUri == www.google.com) { label9.Text = webBrowser1.Url.AbsoluteUri; } This is my current code.
My current code is this $swift = email::connect(); $swift->setSubject('hello') ->setFrom(array('alex@example.com.au' => 'Alex')) ->setTo(array('alex@example.com.au' =>
This is my current search code. -(void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope { [filteredList removeAllObjects]; for(Location
This question is related to a previous question of mine That's my current code
I'm running code that sometimes yields this: UInt32 current; int left, right; ... //sometimes

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.