2010-11-08 58 views
0

代碼如下:爲什麼不能將Symbian CRSAPublicKey轉換爲描述符?

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 

誰能告訴我爲什麼BufferLC()不工作是重要的事情,我只是錯過了,以及如何將TInterger轉換爲描述符??? 在此先感謝。

回答

0

它不是亂碼,它只是整數的二進制表示as stated in the documentation。與字節0x33相同的方式是ASCII 3的二進制表示。

我假設你想要一些可打印的TInteger。對於IsConvertableToLong()爲真的小型TInteger s,您可以使用ConvertToLong()方法與TDes::AppendNum()重載之一。對於較大的整數,我認爲你需要推出自己的轉換函數。最直接的方法可能只是將二進制表示字節輸出爲十六進制。


編輯添加:這是一個未經測試的代碼片段,用於執行十六進制轉換。

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[] = "abcdef"; 
    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); 
+0

thanks laalto.but如何輸出二進制表示字節爲十六進制? – vincent 2010-11-08 07:43:48

+0

TInterger成員數據:protected://成員數據 \t enum TSign {EPositive = 0,ENegative = 1}; \t TUint iSize; \t TUint iPtr; – vincent 2010-11-08 07:44:16

+0

我嘗試爲(TINT I = 0; I <位/的sizeof(TINT);我++) \t { \t \t //位的屎,因此 \t} – vincent 2010-11-08 07:45:55

相關問題