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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:42:31+00:00 2026-06-13T23:42:31+00:00

I have a RSA public key in String format and I want to encrypt

  • 0

I have a RSA public key in String format and I want to encrypt a string using the same to Base 64. Here is the code that I am using for this:

function encrypt(String pin){ 
  String key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiOnM5t6w2ZD6dpA4/MzSTAOt0IYpnsmGSAIfIVgGntI+fI4wbvUvMIhaLN3fHrjyuNGFdYw+yuoXYkapajt6VTZJniaatSiq6bwQ7R0UAop6haFSAwjnmReqexJvcKyqUsTfcfFypPpsYRewh/48/jmc/6ND+ugxDd52prkPUrbj+nnO0z3DBoUCpgDMRvW2hWXv6kZ654gp+wIAQnxbdwRMy6FZbrHjkA3tc6U0CHK+KjxAfzWAK+yI+ofskM4qk50J7y9hUZ7lLikqWZWKiqh8xiDk1kgu+FIjVh+fylKpa3gWmPPn0fSpBJjuenc1OQVmZ718a3388DjzFlYOLwIDAQAB";
  byte[] sigBytes2 = Base64.decode(key, Base64.DEFAULT);
  Log.d("WS", "new key is: " + key);
  try {
    PublicKey publicKey = KeyFactory.getInstance("RSA")
        .generatePublic(new X509EncodedKeySpec(sigBytes2));
    encryptedBase64PIN = encode(publicKey, pin);
    Log.d("WSA", "encoded key is: " + encryptedBase64PIN);
    // getSecToken();
  } catch (Exception e) {
    e.printStackTrace();
  }
}

public static String encode(Key publicKey, String data)
    throws NoSuchAlgorithmException, NoSuchPaddingException,
    InvalidKeyException, IllegalBlockSizeException, BadPaddingException {

  byte[] byteData = data.getBytes(); // convert string to byte array

  Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");       
  cipher.init(Cipher.ENCRYPT_MODE, publicKey);      
  byte[] encryptedByteData = cipher.doFinal(byteData);

  String s = Base64.encodeToString(encryptedByteData, Base64.NO_WRAP);
  return s; // convert encrypted byte array to string and return it
}

When I send the same output to the server, it says “cannot decrypt the PIN”. Why is this?

  • 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-13T23:42:33+00:00Added an answer on June 13, 2026 at 11:42 pm

    When I send the same output to the server, it says “cannot decrypt the PIN”. Why is this?

    There could be many reasons for this. If you have the code for the server decryption, please add it to your question.

    Reasons may include:

    • Wrong encryption mode. You’ve selected RSA/ECB/NoPadding but perhaps the server is expecting something else?

    • Base64 encoding – is the server definitely expecting this?

    • The message is “cannot decrypt PIN”. If the data you are encrypting is the PIN are you sure you should be encrypting ASCII bytes?

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

Sidebar

Related Questions

The situation: I want an application that encrypts an string using RSA. I have
I'm wondering if it's possible to recover a RSA public key that I have
I have written a BlackBerry app that RSA encrypts a message using PKCS1FormatterEngine. This
I have a string that's encrypted using some crypto classes in Java (RSA/ECB/PKCS1Padding) and
I'm using C# to generate an RSA public/private key to encrypt user information. I
How to do RSA encryption of byte array with base-64 encoded public key? After
Here are my constants //Encryption fields /** Algorithm=RSA Mode=ECB Padding=PKCS1Padding*/ public static final String
I am trying to export a public key from openssl using python. I have
I have this function I am using to decrypt values that works fine on
We have a Java application that stores RSA public keys and allows a user

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.