CryptoBuffer CommonCryptoCipher::EncryptBuffer(const CryptoBuffer& unEncryptedData) { if (m_failure) { AWS_LOGSTREAM_FATAL(CC_LOG_TAG, "Cipher not properly initialized for encryption. Aborting"); return CryptoBuffer(); } CheckInitEncryptor(); size_t lengthWritten = unEncryptedData.GetLength() + (GetBlockSizeBytes() - 1); CryptoBuffer encryptedText(static_cast<size_t>( lengthWritten + (GetBlockSizeBytes() - 1))); CCStatus status = CCCryptorUpdate(m_cryptoHandle, unEncryptedData.GetUnderlyingData(), unEncryptedData.GetLength(), encryptedText.GetUnderlyingData(), encryptedText.GetLength(), &lengthWritten); if (status != kCCSuccess) { m_failure = true; AWS_LOGSTREAM_ERROR(CC_LOG_TAG, "Encryption of buffer failed with status code: " << status); return CryptoBuffer(); } if (lengthWritten < encryptedText.GetLength()) { return CryptoBuffer(encryptedText.GetUnderlyingData(), lengthWritten); } return encryptedText; }
void CSAEXAppUi::encryptBody(CRichText*plainBody,CRichText* cipherBody) { TPtrC16 plainText=_L(""); TCharFormat charFormat; plainBody->GetChars(plainText,charFormat,0); TInt plainLength=plainText.Length(); if(plainLength==iPlainTextLength+1) { TBuf8<iPlainTextLength*2> plainEqv; CnvUtfConverter::ConvertFromUnicodeToUtf8(plainEqv,plainText); TUint8 encryptedString[(iPlainTextLength*iCipherKeyLength*2)] ; TInt counter=0; for (TInt p=0;p<iCipherKeyLength;p++) { for(TInt q=0;q<iPlainTextLength;q++) { encryptedString[counter]= (TUint8)plainEqv[q] + cipherKey[p]; //cipherKey[p]; encryptedString[counter+1]=0; counter+=2; } } TPtrC8 encryptedText(encryptedString,iPlainTextLength*iCipherKeyLength*2); TBuf8<iPlainTextLength*8> encryptedText8; TImCodecB64 base64; base64.Initialise(); base64.Encode(encryptedText,encryptedText8); TBuf16<iPlainTextLength*8> encryptedText16; CnvUtfConverter::ConvertToUnicodeFromUtf8(encryptedText16,encryptedText8); cipherBody->InsertL(0,encryptedText16); } }