×

Discussion Board

Results 1 to 11 of 11

Thread: Using RSA

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    Using RSA

    Does anyone know how to use the RSA data encryption capabilities on the Series 60? We want to do no more than encrypt a block of bytes against an RSA key.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    4
    hi

    same problem. found something?

    cu spax

  3. #3
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    135

    Re: Using RSA encryption

    hi,
    any body plz tell me what is problem with this code

    //cpp file

    #include "RSAAlgo.h"
    #include <cryptopanic.h>

    #include <cryptoasymmetric.h>

    #include <aknnotewrappers.h>




    CRSAAlgo::CRSAAlgo()
    {
    //iRSAPublicKey = NULL;
    //iRSAPrivateKey = NULL;

    //iPKey = NULL;
    //iEncryptor = NULL;
    aModulusBits=0;

    }
    CRSAAlgo::~CRSAAlgo()
    {
    /*iN.Close();
    iE.Close();
    if(iEncryptor)
    {
    delete iEncryptor;
    iEncryptor = NULL;
    }
    if(iPKey)
    {
    delete iPKey;
    iPKey = NULL;
    }*/
    /* if(iPublic)
    {
    delete iPublic;
    iPublic = NULL;
    }
    if(iPrivate)
    {
    delete iPrivate;
    iPrivate = NULL;
    }*/
    }
    CRSAAlgo* CRSAAlgo::NewL(TUint aModulusBits)
    {
    CRSAAlgo *self = CRSAAlgo::NewLC(aModulusBits);
    CleanupStack::Pop(self);
    return self;

    }


    CRSAAlgo* CRSAAlgo::NewLC( TUint aModulusBits)
    {
    CRSAAlgo *self = new (ELeave) CRSAAlgo;
    CleanupStack::PushL(self);



    //iN = RInteger::NewL(aN);
    //iE = RInteger::NewL(aE);



    self->ConstructL(aModulusBits);
    return self;
    }
    void CRSAAlgo::ConstructL(TUint aModulusBits)
    {

    TBuf<100> mess;

    //iRSAKeyPair=CRSAKeyPair::NewL(aModulusBits);

    iRSAKeyPair = CRSAKeyPair::NewL(aModulusBits, EStandardCRT) ;

    const CRSAPublicKey &iRSAPublicKey =iRSAKeyPair->PublicKey() ;

    iEncryptor = CRSAPKCS1v15Encryptor::NewL(iRSAPublicKey);



    mess.Append(_L("public key:"));

    //TInt num(-6);
    //TBuf<8> des;
    //take care of number of digits. if it exceed defined in TBuf<>, 8 here, it gives panic.
    //des.Num(iRSAPublicKey);

    //mess.Copy(des);


    //TBuf<32> buffer; // Make it large enough for str

    //stringToDescriptor(str, text);

    TBuf8<10> text;

    TBuf8<10> cipher;

    text.Copy(_L("Hello"));

    /* TBuf8<64> plaintext;

    plaintext.Append(_L("Hello"));


    HBufC8* plainText = HBufC8::NewLC(64);
    TPtr8 plainTextPtr = plainText->Des();*/

    //iEncryptor.
    EncryptL(text,cipher);

    mess.Append(_L("encrypted string"));

    mess.Copy(cipher);


    // iEncryptor.EncryptL(plainTextPtr,cipher);




    //mess.Append(cipher);

    //TBuf8<64> plaintext;

    //mess.AppendNum(iRSAPublicKey);


    //mess.AppendNum(TInt64(iRSAPublicKey ));

    //mess.AppendNum(iRSAPublicKey);

    const CRSAPrivateKey &iRSAPrivateKey =iRSAKeyPair->PrivateKey();

    //iDecrypter = CRSAPKCS1v15Decryptor::NewL(iRSAPrivateKey);

    TInt err;

    CRSAPKCS1v15Decryptor * decryptor;

    TRAP(err,decryptor= CRSAPKCS1v15Decryptor::NewLC(iRSAPrivateKey));




    mess.Append(_L("private key:"));


    //mess.Copy(iRSAKeyPair);


    CAknInformationNote* note = new (ELeave) CAknInformationNote;

    // note->SetTimeout( CAknNoteDialog::ELongTimeout );

    // TBuf<0x100> buf;

    // buf.Format( _L("HandleGetByAttributeL( %i )"), aStatus );

    note->ExecuteLD( mess);




    //iRSAPublicKey = i
    //iRSAPrivateKey = iRSAKeyPair->PrivateKey();



    /*iPKey = CRSAPublicKey::NewL(iN,iE);
    *
    *

    if(iPKey)
    {
    iEncryptor = CRSAPKCS1v15Encryptor::NewL(*iPKey);
    }
    */
    /*iPrivate=iRSAKeyPair.PrivateKey();
    iPublic=iRSAKeyPair.PublicKey();

    console->Printf(iPrivate);

    console->Printf(iPublic);*/


    //iRSAKeyPair.PrivateKey();
    //iRSAKeyPair.iPrivate=iPrivate=iRSAKeyPair.PrivateKey();


    //iPrivate=
    //iRSAKeyPair.PrivateKey();


    //iPublic=iRSAKeyPair.PublicKey();



    }

    TBool CRSAAlgo::EncryptL(const TDesC8 &aInput,TDes8 &aOutput)
    {
    if(iEncryptor)
    {
    TInt len = iEncryptor->MaxInputLength();
    if(aInput.Length() > len)
    return false;

    TRAPD(retval,iEncryptor->EncryptL(aInput,aOutput));
    if(retval != KErrNone)
    {
    switch(retval)
    {
    case ECryptoPanicOutputDescriptorOverflow:
    {
    retval = 0;
    }
    break;
    case ECryptoPanicPadInputTooLarge :
    {
    retval = 1;
    }
    break;
    case ECryptoPanicInputTooLarge :
    {
    retval = 2;
    }
    break;
    default:
    retval = 3;
    }
    return false;
    }

    return true;
    }

    return false;
    }
    /*

    void CRSAAlgo:ecryptL(const TDesC8 &aInput, TDes8 &aOutput)
    {

    }
    */

    /*
    void CRSAAlgo::stringToDescriptor(const char* aString, TDes& aDescriptor)
    {
    TPtrC8 ptr(reinterpret_cast<const TUint8*>(aString));
    aDescriptor.Copy(ptr);
    }*/



    ///.........h file

    #include <cryptoasymmetric.h>
    #include <signed.h>
    #include <cryptopanic.h>
    //#include <x509keys.h>

    #include <e32base.h>
    #include <e32std.h>
    #include <cryptobasic.h>
    #include <cryptoasymmetric.h>
    #include <hash.h>
    #include <signed.h>

    class CRSAAlgo
    {
    public:
    CRSAAlgo();
    virtual ~CRSAAlgo();

    public:
    static CRSAAlgo* NewL(TUint aModulusBits);
    static CRSAAlgo* NewLC(TUint aModulusBits);

    TBool EncryptL(const TDesC8 &aInput, TDes8 &aOutput);

    //TBuf16<2> text,cipher;

    //void stringToDescriptor(const char* aString, TDes& aDescriptor);

    private:
    void ConstructL(TUint aModulusBits);

    protected:

    //CRSAPublicKey *iPKey;

    //CRSAPKCS1v15Encryptor *iEncryptor;

    //CRSAKeyPair *iRSAKeyPair ;

    TUint aModulusBits;


    protected:

    CRSAKeyPair *iRSAKeyPair ;

    CRSAPKCS1v15Encryptor *iEncryptor;

    //CRSAPKCS1v15Decryptor iDecrypter;


    //CRSAPublicKey iRSAPublicKey ;



    //CRSAPrivateKey iRSAPrivateKey ;


    //static RInteger iN;
    //static RInteger iE;
    };


    #endif /* RSAALGO_H_ */

  4. #4
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146

    Re: Using RSA

    Y dont you tell us what error you are getting with the code and at what line instead :-)
    Cheers,
    Mayank

  5. #5
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    135

    conersion of RSApublic reference to TBuf string

    hi,

    i am doing RSA encryption

    i want to convert refernce of public key class to string so that i can pass to server

    //declaration

    const CRSAPrivateKey &iRSAPrivateKey =iRSAKeyPair->PrivateKey();

    const CRSAPublicKey &iRSAPublicKey =iRSAKeyPair->PublicKey() ;

    i have convert &iRSAPublicKey into TBuf

    i tried lot but fails to convert

    plz help me out from situation

    thanks in advance

  6. #6
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: Using RSA

    AFAIK, you can not convert CRSAPrivateKey to descriptor directly. You can convert modulus (n) and its encryption exponent (e) of RSA public key to descriptor as follows.

    Get exponent using E() method.

    TIneger e = CRSAPublicKey::E();
    HBufC8* pBufferExponent = e.BufferLC() ;

    Similarly get modulus using N() method.

    TIneger n = CRSAPublicKey::N();
    HBufC8* pBufferModulus = n.BufferLC() ;

  7. #7
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    135

    Using RSA

    thanks for quick response

    CRSAPublicKey::E() not allowed to call and using ponter or member

    these methods are protected

    how it is possible to accesss


    TInteger e1 = CRSAPublicKey::E();

    HBufC8* pBufferExponent = e.BufferLC() ;



    TInteger n1 = CRSAPublicKey::N();

    it shows errors const non-static

    plz tell me any solution if possible

  8. #8
    Registered User
    Join Date
    Jun 2008
    Posts
    283

    Question Re: Using RSA

    are u reach for anything about get private key.
    Quote Originally Posted by rahul.shalik.makode View Post
    thanks for quick response

    CRSAPublicKey::E() not allowed to call and using ponter or member

    these methods are protected

    how it is possible to accesss


    TInteger e1 = CRSAPublicKey::E();

    HBufC8* pBufferExponent = e.BufferLC() ;



    TInteger n1 = CRSAPublicKey::N();

    it shows errors const non-static

    plz tell me any solution if possible
    Ahmed Mahfouz
    Researcher
    Handset

  9. #9
    Registered User
    Join Date
    Jun 2008
    Posts
    283

    Question Re: Using RSA

    Quote Originally Posted by savaj View Post
    AFAIK, you can not convert CRSAPrivateKey to descriptor directly. You can convert modulus (n) and its encryption exponent (e) of RSA public key to descriptor as follows.

    Get exponent using E() method.

    TIneger e = CRSAPublicKey::E();
    HBufC8* pBufferExponent = e.BufferLC() ;

    Similarly get modulus using N() method.

    TIneger n = CRSAPublicKey::N();
    HBufC8* pBufferModulus = n.BufferLC() ;
    hi savaj we need E,N for object of class(have value i need it) not class it self and is this value represent key it self and this value represent exponent and modulus and not key but we need key to send another guys to encrypt data or if i put this value in new object of key it can generate to the same in other side or whats abt?
    Ahmed Mahfouz
    Researcher
    Handset

  10. #10
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,752

    Re: Using RSA

    Yes, you need.
    Something like
    Code:
    CRSAKeyPair *keypair=CRSAKeyPair::NewLC(512);
    HBufC8 *publicn=keypair.PublicKey().N().BufferLC();
    HBufC8 *publice=keypair.PublicKey().E().BufferLC();
    then you have to send publicn and publice to the other party, and rebuild the public key there:
    Code:
    RInteger n=RInteger::NewL(publicn);
    RInteger e=RInteger::NewL(publice);
    CRSAPublicKey *publickey=CRSAPublicKey::NewLC(n,e);
    Then you can use publickey with CRSAPKCS1v15Encryptor, and the private key (you can obtain it from keypair) with CRSAPKCS1v15Decryptor.

  11. #11
    Registered User
    Join Date
    Jun 2008
    Posts
    283

    Smile Re: Using RSA

    Quote Originally Posted by wizard_hu_ View Post
    Yes, you need.
    Something like
    Code:
    CRSAKeyPair *keypair=CRSAKeyPair::NewLC(512);
    HBufC8 *publicn=keypair.PublicKey().N().BufferLC();
    HBufC8 *publice=keypair.PublicKey().E().BufferLC();
    then you have to send publicn and publice to the other party, and rebuild the public key there:
    Code:
    RInteger n=RInteger::NewL(publicn);
    RInteger e=RInteger::NewL(publice);
    CRSAPublicKey *publickey=CRSAPublicKey::NewLC(n,e);
    Then you can use publickey with CRSAPKCS1v15Encryptor, and the private key (you can obtain it from keypair) with CRSAPKCS1v15Decryptor.
    are u try this and is generated key with n,e are the same?
    Ahmed Mahfouz
    Researcher
    Handset

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×