Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSA/ECB/PKCS1Padding #407

Closed
tifa-show opened this issue Jun 20, 2016 · 4 comments
Closed

RSA/ECB/PKCS1Padding #407

tifa-show opened this issue Jun 20, 2016 · 4 comments

Comments

@tifa-show
Copy link

Hi

I am new to forge and I am coming from JAVA. Can you please show me how to encrypt using RSA with ECB mode and PKCS1 Padding.

please help am stuck now

thanks

@dlongley
Copy link
Member

You can find examples on how to do RSA-based encryption here:

https://github.com/digitalbazaar/forge#rsa

Specifically, you can do RSA public key encryption with PKCS1 padding like this:

// load public key from PEM-formatted string
var pem = '-----BEGIN PUBLIC KEY...';
var publicKey = forge.pki.publicKeyFromPem(pem);

// convert string to UTF-8 encoded bytes
var buffer = forge.util.createBuffer('Something to encrypt', 'utf8');
var bytes = buffer.getBytes();

// encrypt data with a public key using RSAES PKCS#1 v1.5
var encrypted = publicKey.encrypt(bytes, 'RSAES-PKCS1-V1_5');

// base64-encode encrypted data to send to server
var b64Encoded = forge.util.encode64(encrypted);

@Bibo1978
Copy link

you encrypt data with random key in ECB then you encrypt the key with rsa using pkcs1.5 .. RSA doesn't encrypt ECB symmetric keys do that

Kind Regards,
Ibrahim Magdy

On Jun 20, 2016, at 4:57 PM, Mustafa notifications@github.com wrote:

Hi

I am new to forge and I am coming from JAVA. Can you please show me how to encrypt using RSA with ECB mode and PKCS1 Padding.

please help am stuck now

thanks


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@dlongley
Copy link
Member

dlongley commented Oct 5, 2016

Closing out as resolved, feel free to reopen if necessary.

@JianhuisHuang
Copy link

You can find examples on how to do RSA-based encryption here:

https://github.com/digitalbazaar/forge#rsa

Specifically, you can do RSA public key encryption with PKCS1 padding like this:

// load public key from PEM-formatted string
var pem = '-----BEGIN PUBLIC KEY...';
var publicKey = forge.pki.publicKeyFromPem(pem);

// convert string to UTF-8 encoded bytes
var buffer = forge.util.createBuffer('Something to encrypt', 'utf8');
var bytes = buffer.getBytes();

// encrypt data with a public key using RSAES PKCS#1 v1.5
var encrypted = publicKey.encrypt(bytes, 'RSAES-PKCS1-V1_5');

// base64-encode encrypted data to send to server
var b64Encoded = forge.util.encode64(encrypted);

it's work for me, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants