本文整理汇总了C++中encrypt函数的典型用法代码示例。如果您正苦于以下问题:C++ encrypt函数的具体用法?C++ encrypt怎么用?C++ encrypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encrypt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
system("cls");
do
{
// requests prime number from the user.
printf("Enter a prime number: ");
scanf("%d",&ptest);
// checks if it is prime before assigning it to the 'p' variable.
flag=prime(ptest);
}while(flag==0);
if(flag==1)
p=ptest;
do
{
// requests another prime number from the user.
printf("\nEnter a second prime number: ");
scanf("%d",&qtest);
// checks if it is prime before assigning it to the 'q' variable.
flag=prime(qtest);
}while(flag==0);
if(flag==1)
q=qtest;
// gets the message from the user.
printf("\nEnter message: ");
fflush(stdin);
scanf("%[^\n]%*c",Msg);
len=strlen(Msg);
for(i=0;i!=len;i++)
m[i]=Msg[i];
// calculates the modulus and phi.
n=p*q;
phi=(p-1)*(q-1);
// then e and d.
calcE();
printf("\nPossible values of e and d: ");
for(i=0;i<j-1;i++)
printf("\n%ld\t%ld",e[i],d[i]);
encrypt();
decrypt();
getch();
return(0);
}
开发者ID:sharebear42,项目名称:crypto,代码行数:43,代码来源:RSA.c
示例2: fwrite
void Test_encrypt::stringUnderThanMatrix()
{
input=fopen("test.txt","w+");
char string[50]="Example text for testing this algorithm";
fwrite((void*)string,1,strlen(string),input);
fclose(input);
input=fopen("test.txt","w+");
output=fopen("result.txt","w+");
int vector[5]={0,2,4,3,1};
encrypt(5,8,vector);
fclose(output);
fclose(input);
output=fopen("result.txt","w+");
fread((void*)string,1,100,output);
CFIXCC_ASSERT_EQUALS(string,"Elxrttaia tnighpeos r\0mtfegsomxet inlt");
fclose(output);
}
开发者ID:Chitatsu,项目名称:Encryptor,代码行数:19,代码来源:Test_encrypt.cpp
示例3: encrypt
cryptor &cryptor::get(char *buf,
int max_length,
istream &is,
int &more,
char terminator)
{
is.get(buf, max_length, terminator);
if (is.peek() == terminator)
{
is.get();
more = 0;
}
else
more = 1;
encrypt(buf);
return *this;
}
开发者ID:nmathewson,项目名称:aptor1995,代码行数:19,代码来源:CRYPT.CPP
示例4: main
int main()
{
//nb表示分组长度;nk表示密钥长度
int i,nb,nk;
char str[]="abcd1234567890123456789012345678901212345678901234567890123456789012";
char key[32];
char block[32];
gentables();
strtoHex(str,key);
hextoStr(key,str);
printf("Key=");
for (i=0;i<64;i++)
printf("%c",str[i]);
printf("\n");
for (i=0;i<32;i++)
block[i]=i;
for (nb=4;nb<=8;nb+=2)
for (nk=4;nk<=8;nk+=2)
{
printf("\nBlock Size= %d bits, Key Size= %d bits\n",nb*32,nk*32);
gkey(nb,nk,key);
printf("Plain= ");
for (i=0;i<nb*4;i++)
printf("%02x",block[i]);
printf("\n");
//进行加密
encrypt(block);
//输出密文
printf("Encrypt= ");
for (i=0;i<nb*4;i++)
printf("%02x",(unsigned char)block[i]);
printf("\n");
//进行解密
decrypt(block);
//输出明文
printf("Decrypt= ");
for (i=0;i<nb*4;i++)
printf("%02x",block[i]);
printf("\n");
}
system("pause");
return 0;
}
开发者ID:RUIXUEZHAOFENGNIAN,项目名称:mycode,代码行数:43,代码来源:AES加解密算法1.cpp
示例5: encryptMessage
static inline uint8_t encryptMessage(struct Message* message,
struct Wrapper* wrapper)
{
assert(message->padding >= 36 || !"not enough padding");
encrypt(wrapper->nextNonce,
message,
wrapper->secret,
wrapper->isInitiator,
wrapper->authenticatePackets);
Message_shift(message, 4);
union Headers_CryptoAuth* header = (union Headers_CryptoAuth*) message->bytes;
header->nonce = Endian_hostToBigEndian32(wrapper->nextNonce);
wrapper->nextNonce++;
return wrapper->wrappedInterface->sendMessage(message, wrapper->wrappedInterface);
}
开发者ID:Ralith,项目名称:cjdns,代码行数:19,代码来源:CryptoAuth.c
示例6: main
int main() {
char cxt[512] = {0};
byte key[] = "hello, worldxxyy";
byte pt[] = "this is the plaintext";
byte ct[32] = {0};
byte pt2[32] = {0};
aes.set_key(cxt, key, 16);
encrypt(cxt, pt, sizeof(pt), ct);
printf("cipher text:\n");
hexdump(ct, 32);
decrypt(cxt, ct, 32, pt2);
printf("decrypted text:\n");
hexdump(pt2, 32);
printf("%s\n", pt2);
return 0;
}
开发者ID:GaloisInc,项目名称:llvm-verifier,代码行数:19,代码来源:aes-driver.c
示例7: fileStream
/**
* @brief Writes to file associated with the calling object. If a valid key
* is available, data is encrypted (AES-GCM) prior to writing.
*
* @param ss const reference to a string stream with data.
* @param key const reference to a byte vector with the encryption key.
*
* @return true, if data was sucessfully written to file.
*/
bool FileCryptopp::writeFile(
const std::stringstream& ss,
const std::vector<uint8_t>& key
) {
// Start a file stream.
std::ofstream fileStream(_filename, std::ios::binary);
// Check if file stream is open.
if (!fileStream.is_open()) {
return false;
}
// Initialize an ostream_iterator to write to the file stream.
std::ostream_iterator<uint8_t> oit(fileStream);
// Check if encyption key is provided.
if (!key.empty()) {
// Check if encryption key has length equal to default AES key length.
if (key.size() != FileCryptopp::AESNODE_DEFAULT_KEY_LENGTH_BYTES) {
// Invalid key.
std::cout << "Invalid key length";
return false;
}
// Vector to store encrypted bytes of data.
std::vector<uint8_t> cipherData;
// Attempt to encrypt input stream ss and load bytes into cipherData.
if (!encrypt(ss, cipherData, key)) {
// Failed encryption.
return false;
}
// Write encrypted bytes from cipherData to file as chars.
std::copy(cipherData.begin(), cipherData.end(), oit);
} else {
// Write to file without encryption.
fileStream << ss.str();
}
fileStream.close();
return true;
}
开发者ID:kleopatra999,项目名称:seifrng,代码行数:52,代码来源:fileCryptopp.cpp
示例8: strlen
/*
* encrypt(keySize,password,original_message,encrypted_message, mode, padding)
* - encrypts a message using AES Algorithm
*
* Parameters:
* keySize : Size of key to use in AES Algorithm
* password: Key to encrypt plaintext message.
* original_message: Plaintext message before calculating AES Algorithm
* encrypted_message: Ciphertext message after calculating AES Algorithm
* mode: cipher mode, two ways: ECB
* padding: padding mode to fill blocks, tree ways PKCS5, ZEROS, X923
*
* Examples:
* AES.encrypt(128,"libelium","Libelium",encrypted_message,ECB,PKCS5)
*
*/
uint8_t WaspAES::encrypt( uint16_t keySize
, char* password
, char original_message[]
, uint8_t* encrypted_message
, uint8_t mode
, uint8_t padding)
{
// Calculate length of the original message
uint16_t original_length;
original_length = strlen(original_message);
return encrypt( keySize,
password,
(uint8_t*) original_message,
original_length,
encrypted_message,
mode,
padding);
}
开发者ID:AppSaloon,项目名称:waspmoteapi,代码行数:35,代码来源:WaspAES.cpp
示例9: main
int main(int argc, string argv[])
{
//validate command line args
if (argc != 2)
{
printf("You must supply at minimum and at most one command line argument. e.g. ./caeser 4. PLEASE TRY AGAIN!!!!\n");
return 1;
}
//convert string input to int
int rotateBy = atoi(argv[1]);
string plainTextMessage = GetString();
for(int i = 0, len = strlen(plainTextMessage); i < len; i++){
printf("%c", encrypt(plainTextMessage[i], rotateBy));
}
printf("\n");
}
开发者ID:tschf,项目名称:scratch,代码行数:19,代码来源:caesar.c
示例10: encrypt_cmd
static TACommandVerdict encrypt_cmd(TAThread thread,TAInputStream stream)
{
char* block;
int edflag;
// Prepare
block=(char*)readPointer(&stream);
edflag=readInt(&stream);
START_TARGET_OPERATION(thread);
errno=0;
encrypt(block, edflag);
END_TARGET_OPERATION(thread);
// Response
writePointer(thread, block);
writeInt(thread, errno);
sendResponse(thread);
return taDefaultVerdict;
}
开发者ID:levenkov,项目名称:olver,代码行数:43,代码来源:crypt_agent.c
示例11: f5star
void f5star(u8* keyArr, u8* sqn_ak) {
u8* out5;
out5 = malloc(16);
for (i = 0; i < 16; i++) {
out5[i] = temp[i] ^ opc[i];
}
convertToBin(out5, binArr);
rotWord(binArr, 128, 0x08);
convertToHex(binArr, out5);
for (i = 0; i < 16; i++) {
out5[i] ^= c5[i];
}
encrypt(out5, keyArr, out5);
for (i = 0; i < 16; i++) {
out5[i] ^= opc[i];
}
printf("\r\nAK (f5*): ");
for (i = 0; i < 6; i++) {
ak[i] = out5[i];
printf("%02x", ak[i]);
}
for (i = 0; i < 6; i++) {
sqn[i] = ak[i] ^ sqn_ak[i];
}
u8 ind = (sqn[5] & 0b00011111);
u8 seq = (sqn[5] & 0b11100000);
ind = (ind + 1) % 32;
sqn[5] = 0;
sqn[5] |= ind;
seq += 0b00100000;
if (seq == 0) {
sqn[4] += 1;
}
sqn[5] |= seq;
}
开发者ID:sim-authentication,项目名称:document,代码行数:43,代码来源:milenage.c
示例12: memcpy
void SparkProtocol::variable_value(unsigned char *buf,
unsigned char token,
unsigned char message_id_msb,
unsigned char message_id_lsb,
double return_value)
{
buf[0] = 0x61; // acknowledgment, one-byte token
buf[1] = 0x45; // response code 2.05 CONTENT
buf[2] = message_id_msb;
buf[3] = message_id_lsb;
buf[4] = token;
buf[5] = 0xff; // payload marker
memcpy(buf + 6, &return_value, 8);
memset(buf + 14, 2, 2); // PKCS #7 padding
encrypt(buf, 16);
}
开发者ID:adeeshag,项目名称:particle_project,代码行数:19,代码来源:spark_protocol.cpp
示例13: main
void main()
{ struct block data,key,temp;
//unsigned char c1[16]={0x32,0x88,0x31,0xe0,0x43,0x5a,0x31,0x37,0xf6,0x30,0x98,0x07,0xa8,0x8d,0xa2,0x34};
//unsigned char c2[16]={0x2b,0x28,0xab,0x09,0x7e,0xae,0xf7,0xcf,0x15,0xd2,0x15,0x4f,0x16,0xa6,0x88,0x3c};
unsigned char c1[16]="Hello World. 123";
unsigned char c2[16]="My New Password.";
int i,j,c=0;
struct block round_key[11];
// Initializing Data and Key
for(i=0;i<4;i++)
{ for(j=0;j<4;j++)
{ data.b[i][j]=c1[c];
key.b[i][j]=c2[c];
c++;
}
}
printf("Data and key before encryption:");
printf("\n Data:\n");
print_block(data);
printf("\n Key:\n");
print_block(key);
printf("Generating All the round Keys:");
round_key[0]=key;
temp=key;
for(i=0;i<10;i++)
{ temp=next_key(temp,i);
round_key[i+1]=temp;
}
printf("All the keys generated.");
data=encrypt(data,round_key);
printf("Data after encryption:");
printf("\n Data:\n");
print_block(data);
printf("\nData After Decryption\n");
data=decrypt(data,round_key);
print_block(data);
}
开发者ID:WayWingsDev,项目名称:CryptoLibAES-128,代码行数:42,代码来源:test.c
示例14: main
int main(int argc, char* argv[])
{
if (argc < 2)
{
showHelpAndExitWithCode(1);
}
// modernize the arguments, because passing arrays is a nightmare
std::vector<std::string> args(argv, argv + argc);
try
{
for (int i = 0; i < args.size(); i++)
{
if (args.at(i).compare("-e") == 0)
{
encrypt(args, i);
break;
}
if (args.at(i).compare("-d") == 0)
{
decrypt(args, i);
break;
}
if (args.at(i).compare("-a") == 0)
{
analyze(args, i);
break;
}
if (i == args.size() - 1)
{
showHelpAndExitWithCode(1);
}
}
}
catch (std::runtime_error &ex)
{
std::cout << ex.what() << std::endl;
}
return 0;
}
开发者ID:akiraaisha,项目名称:steganographizer,代码行数:42,代码来源:main.cpp
示例15: SecureStorage_RemoveItem
bool SecureStorage_RemoveItem(const SecureStorageS *storage, const unsigned char *sKey, int16_t keyLen) {
int16_t saltLen = 0;
bool ret = false, ret1 = false;
unsigned char *caEncKey = NULL, *rKey = NULL, *caKey = NULL;
unsigned char cahKey[SHA256_LEN + UTILS_STR_LEN_SIZE + 1];
if (storage == NULL || sKey == NULL) {
snprintf(errStr, sizeof(errStr), "SecureStorage_RemoveItem: Storage and key must not be NULL");
return false;
}
if (keyLen <= 0) {
snprintf(errStr, sizeof(errStr), "SecureStorage_RemoveItem: key len %d must be positives\n", keyLen);
return false;
}
if (READABLE_STORAGE == true)
saltLen = 0;
else if (Utils_GetCharArrayLen(storage->caSalt, &saltLen, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN) == false)
return false;
if (generateAlignedCharAray(sKey, keyLen, storage->caSalt, saltLen, &caKey) == false) return false;
if (isLengthValid(caKey, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN - 1) == false || getRandomFromKey(storage, caKey, cahKey, &rKey) == false) {
Utils_Free(caKey);
return false;
}
ret1 = clearKey(storage, cahKey);
if (ret1 == false) { // continue to try to remove the "real" key value
snprintf(errStr, sizeof(errStr), "Error: key for random '%s' was not found", cahKey);
}
ret = encrypt(caKey, rKey, storage->caSecret, &caEncKey);
Utils_Free(rKey);
if (ret == false) {
Utils_Free(caKey);
return false;
}
if (clearKey(storage, caEncKey) == false) {
Utils_Free(caEncKey);
snprintf(errStr, sizeof(errStr), "Error: key '%s' was not found", caKey);
return false;
}
Utils_Free(caKey);
Utils_Free(caEncKey);
return ret1;
}
开发者ID:ibm-security-innovation,项目名称:libsecurity-c,代码行数:42,代码来源:secureStorage.c
示例16: switch
bool ConnectionFactory::createRemoteConnection(const enum ngsCatalogObjectType type,
const std::string &path,
const Options &options)
{
switch(type) {
case CAT_CONTAINER_NGW:
{
std::string url = options.asString(KEY_URL);
if(url.empty()) {
return errorMessage(_("Missing required option 'url'"));
}
std::string login = options.asString(KEY_LOGIN);
if(login.empty()) {
login = "guest";
}
else {
std::string oldLogin(login);
login = CPLString(login).Trim();
if(!compare(oldLogin, login, true)) {
warningMessage("Login was trimmed!");
}
}
std::string password = options.asString(KEY_PASSWORD);
bool isGuest = options.asBool(KEY_IS_GUEST);
CPLJSONDocument connectionFile;
CPLJSONObject root = connectionFile.GetRoot();
root.Add(KEY_TYPE, type);
root.Add(KEY_URL, url);
root.Add(KEY_LOGIN, login);
root.Add(KEY_IS_GUEST, isGuest);
if(!password.empty()) {
root.Add(KEY_PASSWORD, encrypt(password));
}
return connectionFile.Save(path);
}
default:
return errorMessage(_("Unsupported connection type %d"), type);
}
}
开发者ID:nextgis,项目名称:nextgis_datastore,代码行数:42,代码来源:connectionfactory.cpp
示例17: QWidget
interface::interface(QWidget *parent)
: QWidget(parent)
{
setWindowTitle(tr("Cryptography Course Software"));
/*create & format*/
appTabs = new QTabWidget(this);
appLayout = new QVBoxLayout(this);
appTitle = new QLabel(tr("<b><font size=5>Convert between Plaintext and ASCII</font></b><br>ASCII is represented in Hex, Integer, or Binary"), this);
appFooter = new QLabel(tr("Cryptography Course Software<br>Ed Schaefer and Cameron Wong<br>Summer 2011"));
edPage = new edPageWidget();
encryptPage = new SAESpageWidget();
decryptPage = new SAESpageWidget();
appTabs->addTab(edPage, tr("Encode/Decode"));
appTabs->addTab(encryptPage, tr("Encrypt"));
appTabs->addTab(decryptPage, tr("Decrypt"));
appTitle->setAlignment(Qt::AlignCenter);
appFooter->setAlignment(Qt::AlignCenter);
appLayout->addWidget(appTitle);
appLayout->addWidget(appTabs);
appLayout->addWidget(appFooter);
/*initialize*/
encryptPage->inputL->setTitle(tr("Plaintext")); //these are the only label differences
encryptPage->convertButton->setText(tr("Encrypt")); //between the two SAES widgets; everything
encryptPage->outputL->setTitle(tr("Ciphertext (Hex)")); //else is reused code
decryptPage->inputL->setTitle(tr("Ciphertext (Hex)"));
decryptPage->convertButton->setText(tr("Decrypt"));
decryptPage->outputL->setTitle(tr("Plaintext"));
/*signals&slots*/
connect(appTabs, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
connect(encryptPage->convertButton, SIGNAL(clicked()), encryptPage, SLOT(encrypt())); //and make sure the "convert"
connect(decryptPage->convertButton, SIGNAL(clicked()), decryptPage, SLOT(decrypt())); //button for each page does the
//correct thing!
}
开发者ID:reolyze,项目名称:sAES-crypto,代码行数:42,代码来源:interface.cpp
示例18: ns_setpassword
void ns_setpassword(User * u, NickCore * nc)
{
int len = 0;
char password[PASSCODELEN];
if (nc->pass)
free(nc->pass);
nc->pass = smalloc(PASSMAX);
/* we'll generate the password just like we
* did for the passcode */
generatePassCode(password);
len = strlen(password);
#ifdef USE_ENCRYPTION
if (encrypt(password, len, nc->pass, PASSMAX) < 0) {
alog("%s: Failed to encrypt password for %s (set)", MYNAME,
nc->display);
notice_lang(s_NickServ, u, NICK_SET_PASSWORD_FAILED);
return;
}
nc->flags |= NI_ENCRYPTEDPW;
#else
strncpy(nc->pass, password, PASSMAX);
#endif
if (do_sendpassword(u, nc, password) != 0)
{
alog(LOG_COULDNT_SENDMAIL, MYNAME, nc->display);
return;
}
notice(s_NickServ, u->nick, "Your password has been changed successfully. Your new password has been e-mailed to you.");
alog("%s: Password reset for %s (e-mail: %s) by %s!%[email protected]%s.", MYNAME,
nc->display, nc->email, u->nick, u->username, u->host);
return;
}
开发者ID:SwiftIRC,项目名称:services,代码行数:42,代码来源:ns_resetpass.c
示例19: crypto
static int crypto(unsigned char *password, int len, const char *path_passwd, const char *path_key)
{
int ret = -1;
char extkey[DATA_SIZE] = {0};
char clrkey[DATA_SIZE], ecpkey[DATA_SIZE];
unsigned char m[SHA256_DIGEST_LENGTH];
for(ret = 0; ret < len; ret++) {
password[ret] |= 0x60;
}
printf("crypto path, password: %s, key: %s\n", path_passwd, path_key);
crypto_sha(password, len, m);
ret = write_bytes(path_passwd, m, SHA256_DIGEST_LENGTH);
if (ret < 0) {
printf("write passwd to %s failed\n", path_passwd);
goto error;
}
ret = property_set(PROPERTY_PASSWORD_PATH, path_passwd);
if (ret < 0) {
printf("setproperty failed\n");
goto error;
}
generate_combo_key(clrkey, DATA_SIZE);
printf("combo key: %s\n", clrkey);
encrypt((char *)password, clrkey, strlen(clrkey), ecpkey);
ret = write_bytes(path_key, (unsigned char*)ecpkey, strlen(clrkey));
if (ret < 0) {
printf("write key to %s failed\n", path_key);
goto error;
}
ret = property_set(PROPERTY_KEY_PATH, path_key);
if (ret < 0) {
printf("setproperty failed\n");
goto error;
}
ret = 0;
error:
return ret;
}
开发者ID:wenfengtou,项目名称:android_demo,代码行数:42,代码来源:door.cpp
示例20: main
int main(void) {
FILE *input = fopen( "loop.in", "r" );
if( input == NULL ) {
fprintf( stderr, "Could not open loop.in.\n" );
exit( EXIT_FAILURE );
}
char *string = NULL;
size_t length = getstr( &string, input );
fclose( input );
encrypt( string, length );
FILE *output = fopen( "loop.out", "w" );
fprintf( output, "%zu\n", length );
fprintf( output, "%s\n", string );
fclose( output );
free( string );
return 0;
}
开发者ID:stevenjj,项目名称:c_class,代码行数:20,代码来源:loop.c
注:本文中的encrypt函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论