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

  • Home
  • SEARCH
  • 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 7903875
In Process

The Archive Base Latest Questions

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

I am getting issue on Microsoft internet explorer certificate while encrypt with private key

  • 0

I am getting issue on Microsoft internet explorer certificate while encrypt with private key and decrypt with public key having issue

1) Encrypt working file

public String encryption(String inputData, String key, String certificate) // Certificate is nothing but aliase name
{
    String encriptData = null;

    String verify = checkForCertificateConfig();
    if (!verify.equals("OK")) {
        return verify;
    }
    System.out.println("ENCRYPTION INPUTDATA : " + inputData);
    System.out.println("ENCRYPTION KEY : " + key);
    System.out.println("ENCRYPTION CERTIFICATE : " + certificate);
    try {
        if (key.equalsIgnoreCase("Private")) {
            // System.out.println("ENCRYPTION WITH PRIVATE KEY");
            PrivateKey privateKey = (PrivateKey) keyStore.getKey(
                    certificate, null);
            encriptData = encryptString(inputData, privateKey);
        } else {
            // System.out.println("ENCRYPTION WITH PUBLIC KEY");
            encriptData = encryptString(inputData,
                    keyStore.getCertificate(certificate).getPublicKey());
        }
    } catch (NoSuchPaddingException ex) {
        encriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (IllegalBlockSizeException ex) {
        encriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (NoSuchAlgorithmException ex) {
        encriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (UnrecoverableKeyException ex) {
        encriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (InvalidKeyException ex) {
        encriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (KeyStoreException ex) {
        encriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (BadPaddingException ex) {
        encriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (Exception ex) {
        encriptData = ex.getMessage();
        ex.printStackTrace();

    }
    return encriptData;
}

private String encryptString(String encStr, PrivateKey key)
        throws NoSuchAlgorithmException, NoSuchPaddingException,
        InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
    String encoutStr = null;

    /**
     * first check key generation algorithm and initialize Cipher object
     * according algorithm
     */
    if (key.getAlgorithm().equalsIgnoreCase("RSA")) {
        edCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
    } else if (key.getAlgorithm().equalsIgnoreCase("DSA")) {
        edCipher = Cipher.getInstance("DSA/ECB/PKCS1Padding");
    }

    /**
     * Initialize Cipher Object with Private key and mode of Encryption
     */
    edCipher.init(Cipher.ENCRYPT_MODE, key);
    byte[] buff = encStr.getBytes();
    /**
     * Encrypt the String and get binary data
     */
    byte[] encryptedDataStringBytes = edCipher.doFinal(buff);
    /**
     * Encode the binary data into String formate
     */
    encoutStr = this.bASE64Encoder.encode(encryptedDataStringBytes);

    return encoutStr;
}

2) Decrypt Getting error like

public String decryption(String inputData, String key, String certificate) {
    String decriptData = null;

    String verify = checkForCertificateConfig();
    if (!verify.equals("OK")) {
        return verify;
    }

    System.out.println("DECRYPTION INPUTDATA : " + inputData);
    System.out.println("DECRYPTION KEY : " + key);
    System.out.println("DECRYPTION CERTIFICATE : " + certificate);
    try {
        if (key.equalsIgnoreCase("Private")) {
            // System.out.println("DECRYPTION WITH PRIVATE KEY");
            PrivateKey privateKey = (PrivateKey) keyStore.getKey(
                    certificate, null);
            decriptData = decryptString(inputData, privateKey);
        } else {
            // System.out.println("DECRYPTION WITH PUBLIC KEY");
            decriptData = decryptString(inputData,
                    keyStore.getCertificate(certificate).getPublicKey());
        }
    } catch (NoSuchPaddingException ex) {
        decriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (IllegalBlockSizeException ex) {
        decriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (NoSuchAlgorithmException ex) {
        decriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (UnrecoverableKeyException ex) {
        decriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (InvalidKeyException ex) {
        decriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (KeyStoreException ex) {
        decriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (BadPaddingException ex) {
        decriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (IOException ex) {
        decriptData = ex.getMessage();
        ex.printStackTrace();

    } catch (Exception ex) {
        decriptData = ex.getMessage();
        ex.printStackTrace();

    }
    return decriptData;
}   

private String decryptString(String dncStr, PrivateKey key)
        throws NoSuchAlgorithmException, NoSuchPaddingException,
        InvalidKeyException, IOException, IllegalBlockSizeException,
        BadPaddingException {
    String decStr = null;

    /**
     * first check key generation algorithm and initialize Cipher object
     * according algorithm
     */
    if (key.getAlgorithm().equalsIgnoreCase("RSA")) {
        edCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
    } else if (key.getAlgorithm().equalsIgnoreCase("DSA")) {
        edCipher = Cipher.getInstance("DSA/ECB/PKCS1Padding");
    }
    /**
     * Initialize Cipher Object with Private key and mode of Decryption
     */
    edCipher.init(Cipher.DECRYPT_MODE, key);
    /**
     * Decode the encrypted String convert into binary formate
     */
    byte[] encryptedDataStringBytes = this.bASE64Decoder
            .decodeBuffer(dncStr);
    /**
     * Decrypt the binary data and get Original encrypted String.
     */
    decStr = new String(edCipher.doFinal(encryptedDataStringBytes));

    return decStr;
}

Error like…

javax.crypto.BadPaddingException: Blocktype mismatch: 0
at sun.security.rsa.RSAPadding.unpadV15(Unknown Source)
at sun.security.rsa.RSAPadding.unpad(Unknown Source)
at com.sun.crypto.provider.RSACipher.a(DashoA13*..)
at com.sun.crypto.provider.RSACipher.engineDoFinal(DashoA13*..)
at javax.crypto.Cipher.doFinal(DashoA13*..)
at eTokenApplet.decryptString(eTokenApplet.java:1255)
at eTokenApplet.decryption(eTokenApplet.java:1099)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass$MethodInfo.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass$MemberBundle.invoke(Unknown Source)
at sun.plugin2.liveconnect.JavaClass.invoke0(Unknown Source)
at sun.plugin2.liveconnect.JavaClass.invoke(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$DefaultInvocationDelegate.invoke(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source)
at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
  • 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-03T09:51:30+00:00Added an answer on June 3, 2026 at 9:51 am

    For variable length messages, most encryption/decryption algorithms have a required block size. If the data doesn’t fill the block properly – bad things happen – so you need to pad the data

    More info about padding at http://www.di-mgt.com.au/cryptopad.html

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

Sidebar

Related Questions

I'm having an issue getting the public keys for some of the .net 4.0
I'm getting an issue with the F# powerpack quotation evaluation. open Microsoft.FSharp.Linq.QuotationEvaluation let print
I'm having an issue getting a LINQ query to work. I have this XML:
I'm having an issue getting some code to work. Is there a way to
I'm having an issue getting files loaded into an app called GCS, by dragging
I'm having an issue getting this CSS for a sprite sheet to work on
I'm having an issue getting Appstats to work correctly. Using /appstats or /appstats/stats ends
I'm having an issue getting the correct value from my drop down box. Basically
Currently working on a site built in Django and i'm getting an issue when
I am working with Google Python class exercises where I am getting this issue

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.