Beispiel #1
0
int main()
{
  Cesar c;
  OneTime o("DedeATraversLesBrumes");
  OneTime t("TheCakeIsALie");
  encryptString(c, "Je clair Luc, ne pas ? Ze woudrai un kekos !");
  decryptString(c, "Mi isirb Xhq, ew jvo ? Zf zszjyir fz ytafk !");
  encryptString(c, "KIKOO");
  encryptString(c, "LULZ XD");
  decryptString(c, "Ziqivun ea Ndcsg.Wji !");
  encryptString(t, "Prend garde Lion, ne te trompes pas de voie !");
  encryptString(o, "De la musique et du bruit !");
  encryptString(t, "Kion li faras? Li studas kaj programas!");
  decryptString(t, "Iyipd kijdp Pbvr, xi le bvhttgs tik om ovmg !");
  decryptString(o, "Gi pa dunmhmp wu xg tuylx !");
  decryptString(t, "Dpsp vm xaciw? Pk cxcvad otq rrykzsmla!");
}
void test_twofish_decrypt_encrypt_null() {
    char *key = NULL;
    char *plainText = NULL;
    enum EncryptionAlgorithm algorithm = TWOFISH;
    initCryptographyModule();
    int plainTextSize = getStringLength(plainText);
    char *cipherText = encryptString(plainText,plainTextSize, key, algorithm);
    char *plainText2 = decryptString(cipherText,plainTextSize, key, algorithm);
    CU_ASSERT_EQUAL(plainText, NULL);
    CU_ASSERT_EQUAL(plainText2, NULL);
    freeCryptographyModuleMemory();
}
Beispiel #3
0
void DbConnectionInfo::readFromSettings()
{
    uuid = Settings::value("uuid").toString();
    title = Settings::value("title").toString();
    environment = (OraExp::ConnectionEnvironment) Settings::value("environment").toInt();
    username = Settings::value("username").toString().toUpper();
    savePassword = Settings::value("savePassword").toBool();
    password = savePassword ? decryptString(Settings::value("password").toString()) : QString();
    type = Settings::value("type").toInt();
    connectionString = Settings::value("connectionString").toString();
    connectAs = (OraExp::ConnectAs) Settings::value("connectAs").toInt();
}
void test_twofish_decrypt_encrypt() {
    char *key = "ldlelslelslelslslflelslalelslssl";
    char *plainText = "ldlelslelslelslslflelslalelslsslldlelslelslelslslflelslalelslssl";
    enum EncryptionAlgorithm algorithm = TWOFISH;
    initCryptographyModule();
    int plainTextSize = getStringLength(plainText);
    char *cipherText = encryptString(plainText,plainTextSize, key, algorithm);
    char *plainText2 = decryptString(cipherText,plainTextSize, key, algorithm);
    CU_ASSERT_STRING_EQUAL(plainText, plainText2);
    freeCryptographyModuleMemory();
    free(cipherText);
    free(plainText2);
}
CFStringRef
SecUnwrapRecoveryPasswordWithAnswers(CFDictionaryRef recref, CFArrayRef answers)
{    
	if(answers == NULL || CFArrayGetCount(answers) < 3) return NULL;

	CFStringRef theLocaleString = (CFStringRef) CFDictionaryGetValue(recref, kSecRecLocale);
	CFDataRef tmpIV = (CFDataRef) CFDictionaryGetValue(recref, kSecRecIV);
	CFDataRef wrappedPassword = (CFDataRef) CFDictionaryGetValue(recref, kSecRecWrappedPassword);
	
	if(theLocaleString == NULL || tmpIV == NULL || wrappedPassword == NULL) {
		return NULL;
	}
	

    CFLocaleRef theLocale = CFLocaleCreate(kCFAllocatorDefault, theLocaleString);
	SecKeyRef wrapKey = secDeriveKeyFromAnswers(answers, theLocale);
	CFRelease(theLocaleString);
	CFRelease(theLocale);
	
    CFDataRef iv = b64decode(tmpIV);
	
	CFStringRef recoveryPassword =  decryptString(wrapKey, iv, wrappedPassword);
	CFRelease(wrapKey);
   
    if(recoveryPassword != NULL) {
    	CFDataRef comphash = createIVFromPassword(recoveryPassword);
       	if(!CFEqual(comphash, iv)) {
            secDebug(ASL_LEVEL_ERR, "Failed reconstitution of password for recovery\n", NULL);
			CFRelease(recoveryPassword);
			recoveryPassword = NULL;
		}
		CFRelease(comphash);
    }
	CFRelease(iv);
	return recoveryPassword;
}
Beispiel #6
0
SmafeAbstractFeatureVector* SmafeStoreDB::readFeatureVector(long fvt_id,
		long track_id, bool load_fvt_info, long file_id, long segmentnr, bool onErrorSilent, bool load_file_id) {
	SmafeAbstractFeatureVector *safv;

	char* s11nbuf = NULL;
	size_t buf_len;
	std::string class_id;
	long file_id_db; // the file_id from the fv record in the db
	std::string s11nbuf_decrypted;

	try {

		// get feature vector as serialized  (raw)
		readFeatureRecord_raw(track_id, segmentnr, fvt_id, s11nbuf, buf_len, class_id,
				file_id_db, load_file_id);

		// check for NULL
		if (s11nbuf != NULL) {

			// decrypt if necessary
			try {
				s11nbuf_decrypted = decryptString(s11nbuf);
			} catch (CryptoPP::Exception& e) {
				if (onErrorSilent) {
					return NULL;
				} else {
					throw "Error decrypting feature vector: " + e.GetWhat();
				}
			}

			/*
			 // check the save operation
			 std::stringstream ssq (std::stringstream::in | std::stringstream::out);
			 {
			 const SmafeNumericFeatureVector rp(10);
			 // xml
			 //boost::archive::xml_oarchive xoa(ssq);
			 //xoa << BOOST_SERIALIZATION_NVP(rp);
			 //text
			 boost::archive::text_oarchive toa(ssq);
			 toa << BOOST_SERIALIZATION_NVP(rp);
			 }
			 */

			{

				// test
				//			strcpy(s11nbuf, "22 serialization::archive 4 0 25 SmafeNumericFeatureVector 1 0   0 0 0 0");
				//			strcpy(s11nbuf, "22 serialization::archive 4 0 25 SmafeNumericFeatureVector 1 0   0 0 60 15.750428559896203 15.835513677740561 14.431150283495295 9.1691797843426137 12.811824920752358 13.586624597153685 11.002659647379955 11.064217292864679 7.9797139825054986 9.9235703018379375 9.2886428424895762 8.0324006306601525 15.276850905877762 6.9980024541539478 6.5534074804978939 8.2741463327244738 5.5196410597310415 7.0535993338265381 12.179729021310999 7.614244901519533 8.2170004314708081 7.2385293826428949 7.670518295296743 7.4098476138708218 9.1962051599756762 22.083150886531712 7.1937839234320631 5.3740144890307757 9.4028271947731152 4.9368000302025195 5.54337365004546 12.558513608835014 5.0464122111050171 5.2942967940821957 5.1293983657093012 4.0150540410477955 4.1744641937907305 4.4020548029323763 6.5890940735936869 4.9097187529569455 3.4772659337619394 5.18100803316465 3.9710662965692674 3.4761336596970747 6.1217972638432858 2.9740695367326637 3.4272158068985425 5.1425586241272487 4.0814512317989635 5.4559700678194245 10.940316799899946 10.544862969781059 4.6729446737166676 3.1199454721889417 4.0808752427976582 3.2306116954569353 2.6467356438540484 4.4918005045229616 2.4698196267397305 2.414333588255281");
				//strcpy(s11nbuf, "22 serialization::archive 4 0 25 SmafeNumericFeatureVector 1 0\0120 0 0 60 15.750428559896203 15.835513677740561 14.431150283495295 9.1691797843426137 12.811824920752358 13.586624597153685 11.002659647379955 11.064217292864679 7.9797139825054986 9.9235703018379375 9.2886428424895762 8.0324006306601525 15.276850905877762 6.9980024541539478 6.5534074804978939 8.2741463327244738 5.5196410597310415 7.0535993338265381 12.179729021310999 7.614244901519533 8.2170004314708081 7.2385293826428949 7.670518295296743 7.4098476138708218 9.1962051599756762 22.083150886531712 7.1937839234320631 5.3740144890307757 9.4028271947731152 4.9368000302025195 5.54337365004546 12.558513608835014 5.0464122111050171 5.2942967940821957 5.1293983657093012 4.0150540410477955 4.1744641937907305 4.4020548029323763 6.5890940735936869 4.9097187529569455 3.4772659337619394 5.18100803316465 3.9710662965692674 3.4761336596970747 6.1217972638432858 2.9740695367326637 3.4272158068985425 5.1425586241272487 4.0814512317989635 5.4559700678194245 10.940316799899946 10.544862969781059 4.6729446737166676 3.1199454721889417 4.0808752427976582 3.2306116954569353 2.6467356438540484 4.4918005045229616 2.4698196267397305 2.414333588255281\012");


				std::stringstream ss(std::stringstream::in
						| std::stringstream::out);
				//				ss << boost_s11n_workaround_135(s11nbuf_decrypted) << std::endl;
				ss << s11nbuf_decrypted << std::endl;

				SMAFELOG_FUNC(SMAFELOG_DEBUG3, std::string(s11nbuf));

				//ss << stringvalues << endl;

				boost::archive::text_iarchive ia(ss);

				// restore  from the archive
				ia >> BOOST_SERIALIZATION_NVP(safv);
			}

			// get info about featurevectortype if desired
			if (load_fvt_info)
				getFeatureVectorMetaInfo(*safv, fvt_id, track_id, file_id);

			// store foreign keys;
			safv->track_id = track_id;
			// if a specific file_id is given, store this one
			// otherweise store the one that comes from the db
			if (file_id < 0)
				safv->file_id = file_id_db;
			else
				safv->file_id = file_id;

		} else { //if (s11nbuf != NULL)
			if (onErrorSilent) {
				return NULL;
			} else {
				throw std::string("Feature vector not found for track_id = "
						+ stringify(track_id) + ", featurevectortype_id = "
						+ stringify(fvt_id));
			}
		}//if (s11nbuf != NULL)

	} // try block