login about faq

I am running into an issue with getting these 2 API's to like each other ;)

General Concept:

  • Server Side - Creates the RSA Public / Private Keys
  • Webmethod Gives the Client Side Java the Public Key.
  • JavaScript uses the Public Key to encrypt the Data and submits to the Server
  • Server Decrypts the Data.

This is the error I am getting back (I verified that I do get an encrypted string from the JavaScript)

    DllDate: Aug 15 2013
    UnlockPrefix: XXXXXXXX
    Username: JOSHDEVVM:.NET v4.5
    Architecture: Little Endian; 32-bit
    Language: .NET 4.0
    VerboseLogging: 0
    usePrivateKey: 1
      KeyType: Private
      InputSize: 86
      Padding: OAEP
      HashAlg: SHA-1
      ParamLen: 0
      ModulusBitLen: 1024
      Input size must be a multiple of modulus length
      ModulusByteLen: 128
    decrypt: Elapsed time: 0 millisec

Here is the code:

(Creating the RSA Key Pairs)

private void CreateRSAKeys()
            // If we already have the Private key we
            // don't want to make a new one
            if (!String.IsNullOrEmpty(PrivateKey))

            // Create the RSA Object
            Chilkat.Rsa rsa = new Chilkat.Rsa();

            // Unlock the RSA Component

            // Set Options
            rsa.EncodingMode = "base64";
            rsa.OaepPadding = true;
            rsa.LittleEndian = false;

            // Generate the Key

            // Add Keys to Session
            Session.Add("PublicKey", rsa.ExportPublicKey());
            Session.Add("PrivateKey", rsa.ExportPrivateKey());


(Webmethod to give the public key)

[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public static String GetRSAPublicKey()
            // Load the PublicKey form Session
            String publicKeyXml = HttpContext.Current.Session["PublicKey"] as String;

            // In case it is not there.
            if (String.IsNullOrEmpty(publicKeyXml))
                return String.Empty;

            // Create the PubicKey Object
            Chilkat.PublicKey publicKey = new Chilkat.PublicKey();

            // Load the Data

            // Return the PEM Format
            return publicKey.GetOpenSslPem();            

(Decyption Method)
private String Decrypt(String EncData)
            // Create the RSA Object
            Chilkat.Rsa rsaDecryptor = new Chilkat.Rsa();

            // Unlock the RSA Component

            // Set Options
            rsaDecryptor.EncodingMode = "base64";            
            rsaDecryptor.OaepPadding = true;
            rsaDecryptor.LittleEndian = false;

            // Load the Private Key

            // Decrypt
            String clearText = rsaDecryptor.DecryptStringENC(EncData, true);

            return clearText;

(JavaScript) (Get the Key via Akax)

function GetRSAKey() {

            var RSAPublicKey;

                type: 'GET',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                async: false,
                url: 'Default.aspx/GetRSAPublicKey',
                success: function (result) {
                    RSAPublicKey = result.d;

            return RSAPublicKey;

(Encrypt on Click)

function ClientClick() {            
            var encrypt = new JSEncrypt();

            var encrypted = encrypt.encrypt($("#UserData").val());

Any help would be greatly appreciated.

asked Jan 07 '15 at 09:56

ColdFireDragon's gravatar image


edited Jan 07 '15 at 10:25

After Posting this Figured out the issue :)

Even though in the code for the JSEncrypt it says it is using the PKCS1 v2.0 padding it is not is is using the PKCS1 v1.5 changed that and it works.


answered Jan 07 '15 at 10:31

ColdFireDragon's gravatar image


Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Jan 07 '15 at 09:56

Seen: 4,859 times

Last updated: Jan 07 '15 at 10:31

powered by OSQA