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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:46:05+00:00 2026-06-12T13:46:05+00:00

I need 2 simple encryption and decryption methods to encrypt a String a in

  • 0

I need 2 simple encryption and decryption methods to encrypt a String a in an ecrypted String b using another String key as Encryption and Decryption key.

I have found this code that seems doing what I need

public class DesEncrypter {
    Cipher ecipher;
    Cipher dcipher;

    DesEncrypter(SecretKey key) {
        try {
            ecipher = Cipher.getInstance("DES");
            dcipher = Cipher.getInstance("DES");
            ecipher.init(Cipher.ENCRYPT_MODE, key);
            dcipher.init(Cipher.DECRYPT_MODE, key);

        } catch (javax.crypto.NoSuchPaddingException e) {
        } catch (java.security.NoSuchAlgorithmException e) {
        } catch (java.security.InvalidKeyException e) {
        }
    }

    public String encrypt(String str) {
        try {
            // Encode the string into bytes using utf-8
            byte[] utf8 = str.getBytes("UTF8");

            // Encrypt
            byte[] enc = ecipher.doFinal(utf8);

            // Encode bytes to base64 to get a string
            return new sun.misc.BASE64Encoder().encode(enc);
        } catch (javax.crypto.BadPaddingException e) {
        } catch (IllegalBlockSizeException e) {
        } catch (UnsupportedEncodingException e) {
        } catch (java.io.IOException e) {
        }
        return null;
    }

    public String decrypt(String str) {
        try {
            // Decode base64 to get bytes
            byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);

            // Decrypt
            byte[] utf8 = dcipher.doFinal(dec);

            // Decode using utf-8
            return new String(utf8, "UTF8");
        } catch (javax.crypto.BadPaddingException e) {
        } catch (IllegalBlockSizeException e) {
        } catch (UnsupportedEncodingException e) {
        } catch (java.io.IOException e) {
        }
        return null;
    }
}

Unfortunately need a fix to works,
I get an error in

sun.misc.BASE64Encoder()

and in

sun.misc.BASE64Decoder()

that ask me to create a base64 encoder and decoder in sun.misc package

How to fix?

  • 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-12T13:46:06+00:00Added an answer on June 12, 2026 at 1:46 pm

    sun.misc.BASE64Encoder and sun.misc.BASE64Decoder do not exist in the Android Java implementation. They are internal only in Oracle’s JDK, although you do have access, they are not guaranteed to be there.

    You can use the android.util.Base64 class to encode and decode base 64 in Android.

    To encode, change:

    return new sun.misc.BASE64Encoder().encode(enc);
    

    to:

    return android.util.Base64.encodeToString(enc, android.util.Base64.DEFAULT);
    

    To decode, change:

    byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
    

    to:

    byte[] dec = android.util.Base64.decode(str, android.util.Base64.DEFAULT);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My requirement is that I need simple encryption/decryption methods in C# to encrypt and
I need a gem to perform simple string encryption and decryption in Ruby for
I need to do simple single-block AES encryption / decryption in my Qt /
I have written some (functional) AES encryption code using Java's built in encryption libraries,
My question is simple I am expecting encryption algorithm, I need to encrypt a
I need a help regarding sound file encryption/decryption. I would like to encrypt a
I'm using the TripleDESCryptoServiceProvider and need to store the encryption key. If I call
I would like to embed some C# .Net code that does some simple Encryption/Decryption
I have simple encrypt function which takes string, convert it to bytes, xor it
I need to do some simple DES encryption in C to interface with some

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.