本文整理匯總了C++中Encrypt函數的典型用法代碼示例。如果您正苦於以下問題:C++ Encrypt函數的具體用法?C++ Encrypt怎麽用?C++ Encrypt使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Encrypt函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: EsealBDOperationQueryReplay
void EsealBDOperationQueryReplay (sEsealBDWorkTypeDef work, CPU_INT8U ch, sEsealBDStateTypeDef state,
sEsealBDSensorTypeDef sensor, FNCT_COMM comm)
{
CPU_INT8U data[SOCKET_HEAD_SIZE + CHIPHERTEXT_HEAD_SIZE + HEAD_HEAD_SIZE + ESEALBD_OPERATION_REPLAY_SIZE_QUERY];
CPU_INT16U len;
CPU_INT32U id;
CPU_INT32U rn;
CPU_INT32U key;
sCiphertextTypeDef *ciphertext;
CPU_INT8U *p;
sHeadTypeDef *head;
sEsealBDOperatioQueryReplayTypeDef *replay;
id = EsealBDGetID();
rn = EsealBDGetRN();
key = EsealBDGetKey();
ciphertext = (sCiphertextTypeDef *)&data[SOCKET_HEAD_SIZE];
ciphertext->id = NToHL(id);
ciphertext->rn = NToHL(rn);
ciphertext->len = NToHS(HEAD_HEAD_SIZE + ESEALBD_OPERATION_REPLAY_SIZE_QUERY);
p = (CPU_INT8U *)&ciphertext->data;
head = (sHeadTypeDef *)p;
replay = (sEsealBDOperatioQueryReplayTypeDef *)&head->data;
replay->id = NToHL(id);
replay->work.period = NToHS(work.period);
replay->work.window = work.window;
replay->work.channel = work.channel;
replay->ch = ch;
replay->state = state;
replay->sensor = sensor;
len = ESEALBD_OPERATION_REPLAY_SIZE_QUERY;
head->len = NToHS(len);
head->type = NToHS(ESEALBD_OPERATION_TYPE_REPLAY_QUERY);
head->crc = NToHS(GetCRC16(&data[SOCKET_HEAD_SIZE + CHIPHERTEXT_HEAD_SIZE + HEAD_CRC_POS],
HEAD_HEAD_SIZE - HEAD_CRC_LEN + len));
Encrypt(id, rn, key, (CPU_INT8U *)&ciphertext->data, NToHS(ciphertext->len));
SocketPackageSend(ESEALBD_OPERATION_PORT, data, CHIPHERTEXT_HEAD_SIZE + HEAD_HEAD_SIZE + len);
comm(data, SOCKET_HEAD_SIZE + CHIPHERTEXT_HEAD_SIZE + HEAD_HEAD_SIZE + len);
}
示例2: PackSetInfoGWQuick
int PackSetInfoGWQuick(char *pdubuf, char *mac, char *password, PKT_SET_INFO_GW_QUICK *setting, char *key, int klen)
{
DWORD tid;
char tmpbuf[INFO_PDU_LENGTH];
tid = PackCmdHdr(tmpbuf, NET_CMD_ID_QUICKGW_EX, mac, password);
memcpy(tmpbuf+sizeof(IBOX_COMM_PKT_HDR_EX), setting, sizeof(PKT_SET_INFO_GW_QUICK));
#ifdef ENCRYPTION
Encrypt(klen, key, tmpbuf, INFO_PDU_LENGTH, pdubuf);
#else
memcpy(pdubuf, tmpbuf, INFO_PDU_LENGTH);
#endif
return (tid);
}
示例3: va_start
int RASocket::zprintf( const char * szText, ... )
{
if( !szText ) return 0;
va_list ap;
va_start(ap, szText);
char*megabuffer=new char[1024];
unsigned int sz=vsnprintf(megabuffer,1024,szText,ap);
#ifdef RA_CRYPT
Encrypt(megabuffer,sz);
#endif
send(r,megabuffer,sz,0);
delete [] megabuffer;
va_end(ap);
return 0;
}
示例4: va_start
/// Output function
int RASocket::zprintf( const char * szText, ... )
{
if( !szText ) return 0;
va_list ap;
va_start(ap, szText);
/// \todo Remove buffer length here. Can be >1024 (e.g. list of users)
char *megabuffer=new char[1024];
unsigned int sz=vsnprintf(megabuffer,1024,szText,ap);
#ifdef RA_CRYPT
Encrypt(megabuffer,sz);
#endif
send(r,megabuffer,sz,0);
delete [] megabuffer;
va_end(ap);
return 0;
}
示例5: RijndaelEncrypt
void RijndaelEncrypt(RijndaelContextPtr context,void* pInput,unsigned int nSize,void* pOutput)
{
unsigned int i;
//需要計算的最小長度
unsigned int plainSize = context->plainSize;
if (nSize % plainSize != 0)
{
nSize += plainSize - (nSize % plainSize);
//清0
memset((unsigned char*)pOutput + nSize,0,plainSize - (nSize % plainSize));
}
for (i=0; i<nSize; i += plainSize)
{
memcpy((unsigned char*)pOutput + i,(unsigned char*)pInput + i,plainSize);
Encrypt(context,(unsigned char*)pOutput + i);
}
}
示例6: Encrypt_Test
int Encrypt_Test(PRE_KEY *key)
{
int j = g_time;
while(j--)
{
int i = r_time;
Cipher *C = Encrypt(key->pk,m);
begin = clock();
while(i--) {OPENSSL_free(Decrypt(key,C));}
end = clock();
C->~pre_cipher_st();
printf("%d:Encrypt : %f ms...\n",10-j,(double)(end-begin));
}
return 1;
}
示例7: main
int main()
{
char SourceString[THE_STRING_LENGTH] = "¡££¬¡¢£»£º£¿£¡¡¡ª¡¤¡¥¡§0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789¡®¡¯¡°¡±¡©¡«¡¬¡Ã£¢¡Ã£§£à£ü¡¨¡²¡³¡´¡µ¡¶¡·¡¸¡¹¡º¡»£®¡¼¡½¡¾¡¿£¨£©£Û£Ý£û£ý";
char TargetString[THE_STRING_LENGTH];
printf("The Source String:%s\r\n", SourceString);
Encrypt(SourceString, strlen(SourceString)+1, TargetString, strlen(SourceString)+1);
printf("The Encrypt String:%s\r\n", TargetString);
memset(SourceString, 0, sizeof(char)*THE_STRING_LENGTH);
Decrypt(TargetString, strlen(TargetString)+1, SourceString, strlen(TargetString)+1);
printf("The Decrypt Strng:%s\r\n", SourceString);
getchar();
return 0;
}
示例8: chain
//Decrypt from Input Buffer to Output Buffer
//Returns false if n is multiple of 8
void BlowFish::Decrypt(const unsigned char* in, unsigned char* out, unsigned int n, int iMode)
{
//Check the buffer's length - should be > 0 and multiple of 8
if((n==0)||(n%8!=0))
//throw exception("Incorrect buffer length");
return;
SBlock work;
if(iMode == CBC) //CBC mode, using the Chain
{
SBlock crypt, chain(m_oChain);
for(; n >= 8; n -= 8, in += 8)
{
BytesToBlock(in, work);
crypt = work;
Decrypt(work);
work ^= chain;
chain = crypt;
BlockToBytes(work, out+=8);
}
}
else if(iMode == CFB) //CFB mode, using the Chain, not using Decrypt()
{
SBlock crypt, chain(m_oChain);
for(; n >= 8; n -= 8, in += 8)
{
BytesToBlock(in, work);
Encrypt(chain);
crypt = work;
work ^= chain;
chain = crypt;
BlockToBytes(work, out+=8);
}
}
else //ECB mode, not using the Chain
{
for(; n >= 8; n -= 8, in += 8)
{
BytesToBlock(in, work);
Decrypt(work);
BlockToBytes(work, out+=8);
}
}
}
示例9: Keygen
bool RSA::DefaultTest(unsigned int size)
{
if(size < 64)
{
std::cout << "RSA test invald input\n";
return false;
}
BigInteger pub, priv, modulus;
Utils::TestGenerator generator;
Keygen(pub, priv, modulus, &generator, size);
BigInteger message = generator.getBig(size) % modulus;
BigInteger crypto = Encrypt(message, pub, modulus);
BigInteger message1 = Decrypt(crypto, priv, modulus);
bool result = (message1 == message);
if(result)
std::cout << "RSA test OK\n";
else std::cout << "RSA test ERROR\n";
return result;
}
示例10: ParallelKeygen
bool RSA::CustomTest(unsigned int size, Utils::Generator *generator, int threads, unsigned int precision, unsigned int distance)
{
if(size < 64 || generator == NULL)
{
std::cout << "RSA test invalid input\n";
return false;
}
BigInteger pub, priv, modulus;
ParallelKeygen(pub, priv, modulus, generator, size, threads, precision, distance);
BigInteger message = generator->getBig(size) % modulus;
BigInteger crypto = Encrypt(message, pub, modulus);
BigInteger message1 = Decrypt(crypto, priv, modulus);
bool result = message1 == message;
if(result)
std::cout << "RSA test OK\n";
else std::cout << "RSA test ERROR\n";
return result;
}
示例11: main
int main(void)
{
HCRYPTPROV hCryptProv = 0;
HCRYPTKEY key = 0;
unsigned long cLen = 0;
char *cipherText = 0;
char *plainText = "PLAIN_TEXT_PLAIN_TEXT\0";
char *password = "!TESTING_PASS_TESTING_PASS!\0";
unsigned char *decrypted = 0;
if (!CryptoInit(&key, &hCryptProv, password, strlen(password)))
{
printf("Crypto initializing failed\n");
return EXIT_FAILURE;
}
if (!Encrypt(key, &cipherText, &cLen, (unsigned char *)plainText, strlen(plainText)))
{
printf("Encryption failed\n");
if (hCryptProv) CryptReleaseContext(hCryptProv, 0);
return EXIT_FAILURE;
}
printf("Encrypted string: %s\n", cipherText);
if (!Decrypt(key, &decrypted, cipherText, cLen))
{
printf("Decryption failed\n");
SAFE_FREE(cipherText);
if (hCryptProv) CryptReleaseContext(hCryptProv, 0);
return EXIT_FAILURE;
}
SAFE_FREE(cipherText);
printf("Decrypted string: %s\n", decrypted);
SAFE_FREE(decrypted);
CryptoUninit(key, hCryptProv);
return EXIT_SUCCESS;
}
示例12: main
int main()
{
int i,n;
char s[80],key[12],encrypt[80]; //輸入串,密鑰,加密後的串
scanf("%s",key);
getchar(); //吃掉輸入密鑰後的那個回車
GeneAlphabet(); //產生字母表
Reverse(key); //將密鑰key反轉
GetCharMap(key); //得到字母表的加密字符的對應表
while(1)
{
gets(s); //得到每行要加密的串
if(strcmp(s,"#") == 0) break; //如果輸入#號則終止程序
strcpy(encrypt,""); //將加密後的串先清空
Encrypt(s,key,encrypt); //加密
puts(encrypt); //輸出
}
return 0;
}
示例13: Java_com_softtanck_tanck_aes_utils_AesUtils_Encrypt
/*********************加密*********************/
JNIEXPORT jint JNICALL Java_com_softtanck_tanck_aes_utils_AesUtils_Encrypt(JNIEnv *env,
jclass thiz,
jbyteArray msg,
jbyteArray key,
jbyteArray cipher,
jint length) {
jbyte *pMsg = (jbyte *) (*env)->GetByteArrayElements(env, msg, 0);
jbyte *pKey = (jbyte *) (*env)->GetByteArrayElements(env, key, 0);
jbyte *pCipher = (jbyte *) (*env)->GetByteArrayElements(env, cipher, 0);
if (!pMsg || !pKey || !pCipher) {
return -1;
}
int flag = Encrypt(pMsg, pKey, pCipher, length); //加密函數
(*env)->ReleaseByteArrayElements(env, msg, pMsg, 0);
(*env)->ReleaseByteArrayElements(env, key, pKey, 0);
(*env)->ReleaseByteArrayElements(env, cipher, pCipher, 0);
return flag;
}
示例14: EsealBDOperationError
void EsealBDOperationError (CPU_INT8U error, FNCT_COMM comm)
{
CPU_INT8U data[SOCKET_HEAD_SIZE + CHIPHERTEXT_HEAD_SIZE + HEAD_HEAD_SIZE + ESEALBD_OPERATION_REPLAY_SIZE_ERROR];
CPU_INT16U len;
CPU_INT32U id;
CPU_INT32U rn;
CPU_INT32U key;
sCiphertextTypeDef *ciphertext;
CPU_INT8U *p;
sHeadTypeDef *head;
sEsealBDOperatioErrornReplayTypeDef *replay;
id = EsealBDGetID();
rn = EsealBDGetRN();
key = EsealBDGetKey();
ciphertext = (sCiphertextTypeDef *)&data[SOCKET_HEAD_SIZE];
ciphertext->id = NToHL(id);
ciphertext->rn = NToHL(rn);
ciphertext->len = NToHS(HEAD_HEAD_SIZE + ESEALBD_OPERATION_REPLAY_SIZE_ERROR);
p = (CPU_INT8U *)&ciphertext->data;
head = (sHeadTypeDef *)p;
replay = (sEsealBDOperatioErrornReplayTypeDef *)&head->data;
replay->id = NToHL(id);
replay->error = error;
len = ESEALBD_OPERATION_REPLAY_SIZE_ERROR;
head->len = NToHS(len);
head->type = NToHS(ESEALBD_OPERATION_TYPE_REPLAY_ERROR);
head->crc = NToHS(GetCRC16(&data[SOCKET_HEAD_SIZE + CHIPHERTEXT_HEAD_SIZE + HEAD_CRC_POS],
HEAD_HEAD_SIZE - HEAD_CRC_LEN + len));
Encrypt(id, rn, key, (CPU_INT8U *)&ciphertext->data, NToHS(ciphertext->len));
SocketPackageSend(ESEALBD_OPERATION_PORT, data, CHIPHERTEXT_HEAD_SIZE + HEAD_HEAD_SIZE + len);
comm(data, SOCKET_HEAD_SIZE + CHIPHERTEXT_HEAD_SIZE + HEAD_HEAD_SIZE + len);
}
示例15: chain
//Decrypt Buffer in Place
//Returns false if n is multiple of 8
void CBlowFish::Decrypt(unsigned char* buf, size_t n, int iMode)
{
//Check the buffer's length - should be > 0 and multiple of 8
if((n==0)||(n%8!=0))
throw std::exception("Incorrect buffer length");
SBlock work;
if(iMode == CBC) //CBC mode, using the Chain
{
SBlock crypt, chain(m_oChain);
for(; n >= 8; n -= 8)
{
BytesToBlock(buf, work);
crypt = work;
Decrypt(work);
work ^= chain;
chain = crypt;
BlockToBytes(work, buf+=8);
}
}
else if(iMode == CFB) //CFB mode, using the Chain, not using Decrypt()
{
SBlock crypt, chain(m_oChain);
for(; n >= 8; n -= 8)
{
BytesToBlock(buf, work);
Encrypt(chain);
crypt = work;
work ^= chain;
chain = crypt;
BlockToBytes(work, buf+=8);
}
}
else //ECB mode, not using the Chain
{
for(; n >= 8; n -= 8)
{
BytesToBlock(buf, work);
Decrypt(work);
BlockToBytes(work, buf+=8);
}
}
}