2

How to do ECB mode when dealing with RSA? I dont understand it. The Aadhar authentication doc (http://uidai.gov.in/images/FrontPageUpdates/aadhaar_authentication_api_1_6.pdf Page 33) says that we have to use RSA/ECB/PKCS1Padding but I am not finding any references to mode when dealing with RSA.

  • We generate a AES-256 session key on server and send to client. (We forget the session key)
  • Client encrypts his data block with symmetric AES/ECB/PKCS7Padding (using cryptojs)
  • Client encrypts his session key with 2048-bit Aadhar public key using asymmetric algorithm (RSA/ECB/PKCS1Padding)
  • Client also calculates HMAC of Data Block
  • Client sends us the three fields, the server fills in other data and sends to Aadhar server

So we need to do RSA/ECB/PKCS1Padding in the web client in Javascript. CryptoJS doesnot support RSA so you can use any other library

If somebody can tell me if the Forge library's example

var encrypted = publicKey.encrypt(bytes, 'RSAES-PKCS1-V1_5');

uses ECB or not. There are references to RSA/ECB/OAEPWithSHA-256AndMGF1Padding but I need PKCS#1 padding

Can you suggest me any other library or tell me proper code in Forge?

If I can do this in PHP on server side then also I can send session key and encrypted session key to client and then forget the session key.

I donot understand much cryptography but understand the terms somewhat.

  • I'm not saying that this is THE answer but I think that your framework works for both type of ciphers and thus requires a mode before allowing you to specify a padding scheme. In that case ECB applied to asymetric encryption would mean "do nothing"... Eg. See in Java docs.oracle.com/javase/7/docs/api/javax/crypto/Cipher.html – Cerber Nov 4 '15 at 16:39
1

ECB doesn't even make sense in the context of RSA. It's a mode of operation for symmetric ciphers like AES. More info:

http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#ECB

PKCS1Padding, however, does apply to RSA. And you're right - that likely means RSAES-PKCS1-V1_5. For the PHP side you can use phpseclib. eg.

<?php
include('Crypt/RSA.php');

$rsa = new Crypt_RSA();
$rsa->loadKey('...'); // public key

$plaintext = '...';

$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$ciphertext = $rsa->encrypt($plaintext);

$rsa->loadKey('...'); // private key
echo $rsa->decrypt($ciphertext);
?>

URL: http://phpseclib.sourceforge.net/

  • See my comment in the question : I think it's because his frameworks makes it mandatory to specify a mode before the padding type (although it is useless) – Cerber Nov 4 '15 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.