ash2005 / jcardsim

Automatically exported from code.google.com/p/jcardsim
0 stars 1 forks source link

Implementation of ALG_RSA_PKCS1 algorithm #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Constructor of AssymetricCipherImpl can be changed to the following in order to 
implement ALG_RSA_PKCS1 algorithm:

    public AssymetricCipherImpl(byte algorithm) {

        this.algorithm = algorithm;
        switch (algorithm) {
            case ALG_RSA_NOPAD:
                engine = new RSAEngine();
                paddingEngine = null;
                break;
            case ALG_RSA_PKCS1:
                engine = new PKCS1Encoding(new RSAEngine());
                paddingEngine = null;
                break;
            default:
                CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM);
                break;
        }
    }

Original issue reported on code.google.com by smbl64@gmail.com on 3 Feb 2013 at 8:10

GoogleCodeExporter commented 9 years ago
Also there is a change in the doFinal method for encryption to work:

// RSA PKCS1 engine has its internal padding engine
if (algorithm != ALG_RSA_PKCS1){
    if ((bufferPos < engine.getInputBlockSize()) && (paddingEngine == null)) {
        CryptoException.throwIt(CryptoException.ILLEGAL_USE);
    } else if (bufferPos < engine.getInputBlockSize()) {
        paddingEngine.addPadding(buffer, bufferPos);
    }
}

Original comment by smbl64@gmail.com on 9 Feb 2013 at 7:41

GoogleCodeExporter commented 9 years ago

Original comment by jcard...@licel.ru on 1 Jun 2013 at 2:45