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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:18:28+00:00 2026-06-09T13:18:28+00:00

i generated a public/private keypair using java. Since i want to add the key

  • 0

i generated a public/private keypair using java. Since i want to add the key to my code (not as file) i used

byte[] priv = private_key.getEncoded() 

to get it as a byte array.
To get back the private key from the byte array i use

PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(priv);

Decryption is working as expected.
But now i want to use that key inside a c application using openssl.
So i copied the byte array from java to c as a char[].
But i’m not able to convert this char[] into a private key to use it for decryption via RSA_public_decrypt(…)
I tried

RSA *r = d2i_RSAPrivateKey(NULL,&priv, len);

but this always return a NULL pointer

Can anyone please give me a hint on how to do this in c language?

Edit: Meanwhile i checked the error code from openssl and it says

error:0D0680A8:lib(13):func(104):reason(168)

But i don’t know whet to do with those error codes. A search on the net didn’t help yet.

Many thanks in advance.
Greetings, -chris-

  • 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-09T13:18:29+00:00Added an answer on June 9, 2026 at 1:18 pm

    Thanks to hint from srikanth yaradla i found the right direction.
    Here’s how i did it:

    const unsigned char private_key[] = {0x30,...};
    size_t private_key_len = sizeof(private_key);
    char* buf = (char*)malloc(private_key_len);
    memcpy(buf, private_key, private_key_len);
    BIO* mem=BIO_new_mem_buf(buf, private_key_len);
    PKCS8_PRIV_KEY_INFO* p8inf = d2i_PKCS8_PRIV_KEY_INFO_bio(mem, NULL);
    EVP_PKEY* pkey = EVP_PKCS82PKEY(p8inf);
    RSA* r = EVP_PKEY_get1_RSA(pkey);
    

    after doing that i now can easily decrypt data i get from the java part.

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

Sidebar

Related Questions

i am using a certificate generated by makecert which has both private and public
I have generated a public key, private key pair. I've set the public key
This code generates a pair of public/private keys: KeyPairGenerator keyGen = KeyPairGenerator.getInstance(RSA); keyGen.initialize(1024); KeyPair
I'm trying to import an RSA public/private key pair generated with the Win32 Crypto
I have generated a public/private keypair with Crypto++, and I encode a password on
Hi I have generated a key pair and used the private key to generate
I am trying to generate my first public/private key pair for an RSA encryption.
i have the following code: /** * @generated */ public class foo ... /**
here's the code(Where I think the NullPointerException is generated): public String getData(String s1,String s2,String
Suppose you start with an auto-generated method public void setKey(Key key) { this.key =

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.