why can't convert Symbian CRSAPublicKey to descriptor?

有些话、适合烂在心里 提交于 2019-12-12 01:46:10

问题


code as following:

const CRSAPublicKey& iRSAPublicKey = mRSAKeyPair->PublicKey();
const TInteger& e = iRSAPublicKey.E();
HBufC8* exponent8 = e.BufferLC(); //failed to get the right result,it's garbled
TInt ei = e.ConvertToLongL();    //converted successfully,ei=65537

can anyone tell me why BufferLC() doesn't work?is something important i just have missed?,and how to convert a TInterger to descriptor? thanks in advance.


回答1:


It't not garbled, it just the integer's binary representation as stated in the documentation. The same way as the byte 0x33 is the binary representation for ASCII 3.

I assume you want something printable of the TInteger. For small TIntegers for which IsConvertableToLong() is true, you can use the ConvertToLong() approach with one of the TDes::AppendNum() overloads. For larger integers, I think you need to roll your own conversion function. The most straightforward way is probably just to output the binary representation bytes as hex.


Edited to add: Here's an untested snippet for doing the hex conversion.

HBufC8 *bin = theTInteger.BufferLC();

// One binary byte yields two hex bytes
HBufC8 *output = HBufC8::NewL(bin->Length()*2);
TPtr8 outP = output->Des();

// Loop through the binary bytes  
for (int i = 0; i < bin->Length(); ++i) {
  TUint8 const KHex[] = "01234567890abcdef";
  TUint8 binByte = (*bin)[i];

  // Output high nibble (4 bits)
  outP.Append(KHex[(binByte & 0xf0) >> 4]);

  // Output low nibble
  outP.Append(KHex[binByte & 0x0f]);
}

CleanupStack::PopAndDestroy(bin);


来源:https://stackoverflow.com/questions/4121937/why-cant-convert-symbian-crsapublickey-to-descriptor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!