예제 #1
0
void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename)
{
	FileSource privFile(privFilename, true);
	RSASSA_PKCS1v15_SHA_Signer priv(privFile);
	// RSASSA_PKCS1v15_SHA_Signer ignores the rng. Use a real RNG for other signature schemes!
	FileSource f(messageFilename, true, new SignerFilter(GlobalRNG(), priv, new FileSink(signatureFilename)));
}
예제 #2
0
파일: testSignBug.cpp 프로젝트: nsb/Calypso
void signStringWholeBlock( const char *inString ) {

    // source for our private key file
    FileSource privFile( "privateKey.txt", true, new HexDecoder );

    // construct a hasher/signer using the private key
    RSASSA_PKCS1v15_SHA_Signer priv( privFile );

    // RSASSA_PKCS1v15_SHA_Signer ignores the rng.
    // Use a real RNG for other signature schemes!
    NullRNG rng;

    // a filter based on this signer
    // should put result into signature file
    SignerFilter signer( rng,
                         priv,
                         new HexEncoder(
                             new FileSink( signatureFileName ) ) );


    // pass data blocks through filter as one large block
    int numBytes = strlen( inString );

    signer.Put( (unsigned char *)inString, numBytes );

    // unlimited propagate here to flush file
    signer.MessageEnd( -1 );
}
예제 #3
0
파일: test.cpp 프로젝트: acat/emule
string RSADecryptString(const char *privFilename, const char *ciphertext)
{
	FileSource privFile(privFilename, true, new HexDecoder);
	RSAES_OAEP_SHA_Decryptor priv(privFile);

	string result;
	StringSource(ciphertext, true, new HexDecoder(new PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(result))));
	return result;
}
예제 #4
0
void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed)
{
	RandomPool randPool;
	randPool.Put((byte *)seed, strlen(seed));

	RSAES_PKCS1v15_Decryptor priv(randPool, keyLength);
	FileSink privFile(privFilename);
	priv.DEREncode(privFile);
	privFile.MessageEnd();

	RSAES_PKCS1v15_Encryptor pub(priv);
	FileSink pubFile(pubFilename);
	pub.DEREncode(pubFile);
	pubFile.MessageEnd();
}
예제 #5
0
파일: test.cpp 프로젝트: NotHawthorne/umbra
void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed)
{
	RandomPool randPool;
	randPool.IncorporateEntropy((byte *)seed, strlen(seed));

	RSAES_OAEP_SHA_Decryptor priv(randPool, keyLength);
	HexEncoder privFile(new FileSink(privFilename));
	priv.DEREncode(privFile);
	privFile.MessageEnd();

	RSAES_OAEP_SHA_Encryptor pub(priv);
	HexEncoder pubFile(new FileSink(pubFilename));
	pub.DEREncode(pubFile);
	pubFile.MessageEnd();
}
예제 #6
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CMySplashScreen::SizeChanged()
{	
	TFindFile privFile(CCoeEnv::Static()->FsSession());
	if(KErrNone == privFile.FindByDir(KtxIconFileName, KNullDesC))
	{	
		delete iBackGround;
		iBackGround = NULL;		
		iBackGround = AknIconUtils::CreateIconL(privFile.File(), EMbmYapp_a000312dSplash_back);
		AknIconUtils::SetSize(iBackGround,Rect().Size(),EAspectRatioNotPreserved);	
		
		iBackAdd.ResetAndDestroy();
		iBackAdd.Append(LoadImageL(privFile.File(),EMbmYapp_a000312dSplash,EMbmYapp_a000312dSplash_mask,Rect().Size()));
		iBackAdd.Append(LoadImageL(privFile.File(),EMbmYapp_a000312dSplash2,EMbmYapp_a000312dSplash2_mask,Rect().Size()));
		iBackAdd.Append(LoadImageL(privFile.File(),EMbmYapp_a000312dSplash3,EMbmYapp_a000312dSplash3_mask,Rect().Size()));
	}
}
예제 #7
0
bool ValidateRSA()
{
	cout << "\nRSA validation suite running...\n\n";

	byte out[100], outPlain[100];
	bool pass = true, fail;

	{
		static const char plain[] = "Everyone gets Friday off.";
		byte *signature = (byte *)
			"\x05\xfa\x6a\x81\x2f\xc7\xdf\x8b\xf4\xf2\x54\x25\x09\xe0\x3e\x84"
			"\x6e\x11\xb9\xc6\x20\xbe\x20\x09\xef\xb4\x40\xef\xbc\xc6\x69\x21"
			"\x69\x94\xac\x04\xf3\x41\xb5\x7d\x05\x20\x2d\x42\x8f\xb2\xa2\x7b"
			"\x5c\x77\xdf\xd9\xb1\x5b\xfc\x3d\x55\x93\x53\x50\x34\x10\xc1\xe1";

		FileSource keys("TestData/rsa512a.dat", true, new HexDecoder);
		Weak::RSASSA_PKCS1v15_MD2_Signer rsaPriv(keys);
		Weak::RSASSA_PKCS1v15_MD2_Verifier rsaPub(rsaPriv);

		size_t signatureLength = rsaPriv.SignMessage(GlobalRNG(), (byte *)plain, strlen(plain), out);
		fail = !VerifyBufsEqual(signature, out, 64);
		pass = pass && !fail;

		cout << (fail ? "FAILED    " : "passed    ");
		cout << "signature check against test vector\n";

		fail = !rsaPub.VerifyMessage((byte *)plain, strlen(plain), out, signatureLength);
		pass = pass && !fail;

		cout << (fail ? "FAILED    " : "passed    ");
		cout << "verification check against test vector\n";

		out[10]++;
		fail = rsaPub.VerifyMessage((byte *)plain, strlen(plain), out, signatureLength);
		pass = pass && !fail;

		cout << (fail ? "FAILED    " : "passed    ");
		cout << "invalid signature verification\n";
	}
	{
		FileSource keys("TestData/rsa1024.dat", true, new HexDecoder);
		RSAES_PKCS1v15_Decryptor rsaPriv(keys);
		RSAES_PKCS1v15_Encryptor rsaPub(rsaPriv);

		pass = CryptoSystemValidate(rsaPriv, rsaPub) && pass;
	}
	{
		RSAES<OAEP<SHA> >::Decryptor rsaPriv(GlobalRNG(), 512);
		RSAES<OAEP<SHA> >::Encryptor rsaPub(rsaPriv);

		pass = CryptoSystemValidate(rsaPriv, rsaPub) && pass;
	}
	{
		byte *plain = (byte *)
			"\x54\x85\x9b\x34\x2c\x49\xea\x2a";
		byte *encrypted = (byte *)
			"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a"
			"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4"
			"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52"
			"\x62\x51";
		byte *oaepSeed = (byte *)
			"\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2"
			"\xf0\x6c\xb5\x8f";
		ByteQueue bq;
		bq.Put(oaepSeed, 20);
		FixedRNG rng(bq);

		FileSource privFile("TestData/rsa400pv.dat", true, new HexDecoder);
		FileSource pubFile("TestData/rsa400pb.dat", true, new HexDecoder);
		RSAES_OAEP_SHA_Decryptor rsaPriv;
		rsaPriv.AccessKey().BERDecodePrivateKey(privFile, false, 0);
		RSAES_OAEP_SHA_Encryptor rsaPub(pubFile);

		memset(out, 0, 50);
		memset(outPlain, 0, 8);
		rsaPub.Encrypt(rng, plain, 8, out);
		DecodingResult result = rsaPriv.FixedLengthDecrypt(GlobalRNG(), encrypted, outPlain);
		fail = !result.isValidCoding || (result.messageLength!=8) || !VerifyBufsEqual(out, encrypted, 50) || !VerifyBufsEqual(plain, outPlain, 8);
		pass = pass && !fail;

		cout << (fail ? "FAILED    " : "passed    ");
		cout << "PKCS 2.0 encryption and decryption\n";
	}

	return pass;
}
예제 #8
0
/*
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
TBool CMgAppUi::ShowDisclaimerL(void)
{
	TBool OkToContinue(EFalse);

	if(KAppIsTrial){
        TFindFile AppFile(CCoeEnv::Static()->FsSession());
        if(KErrNone != AppFile.FindByDir(KtxDisclaimerFileName, KNullDesC))
        {
            HBufC* Abbout = KtxDisclaimer().AllocLC();
            TPtr Pointter(Abbout->Des());
            CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL(Pointter);
            dlg->PrepareLC(R_DDD_HEADING_PANE);
            dlg->SetHeaderTextL(KtxDisclaimerTitle);  
            if(dlg->RunLD())
            {
                TFileName ShortFil;
                if(KErrNone ==CCoeEnv::Static()->FsSession().PrivatePath(ShortFil))
                {
                    TFindFile privFile(CCoeEnv::Static()->FsSession());
                    if(KErrNone == privFile.FindByDir(ShortFil, KNullDesC))
                    {
                        TParsePtrC hjelp(privFile.File());
                        ShortFil.Copy(hjelp.Drive());
                        ShortFil.Append(KtxDisclaimerFileName);
                    }
                }
    
            
                BaflUtils::EnsurePathExistsL(CCoeEnv::Static()->FsSession(),ShortFil);
            
                RFile MyFile;
                if(KErrNone == MyFile.Create(CCoeEnv::Static()->FsSession(),ShortFil,EFileWrite))
                {
                    TTime NowTime;
                    NowTime.HomeTime();
                    
                    TBuf8<255> InfoLine;
                    InfoLine.Copy(_L8("Accepted on Date\t"));
                        
                    InfoLine.AppendNum(NowTime.DateTime().Day() + 1);
                    InfoLine.Append(_L8("."));
                    InfoLine.AppendNum((NowTime.DateTime().Month() + 1));
                    InfoLine.Append(_L8("."));
                    InfoLine.AppendNum(NowTime.DateTime().Year());
                    InfoLine.Append(_L8(" "));
                    InfoLine.Append(_L8("--"));
                    InfoLine.AppendNum(NowTime.DateTime().Hour());
                    InfoLine.Append(_L8(":"));		
                    TInt HelperInt = NowTime.DateTime().Minute();
                    if(HelperInt < 10)
                        InfoLine.AppendNum(0);
                    InfoLine.AppendNum(HelperInt);
                    InfoLine.Append(_L8(":"));
                    HelperInt = NowTime.DateTime().Second();
                    if(HelperInt < 10)
                        InfoLine.AppendNum(0);
                    InfoLine.AppendNum(HelperInt);
                    InfoLine.Append(_L8(" "));
                    
                    MyFile.Write(InfoLine);
                    MyFile.Close();
                }
                
                OkToContinue = ETrue;
            }
            
            CleanupStack::PopAndDestroy(Abbout);
        }
        else
        {
            OkToContinue = ETrue;
        }
	}
    else
    {
        OkToContinue = ETrue;
    }
	
	return OkToContinue;
}
예제 #9
0
파일: validat2.cpp 프로젝트: mentat/nnim
bool RSAValidate()
{
	cout << "\nRSA validation suite running...\n\n";

	byte out[100], outPlain[100];
	unsigned int outLen;
	bool pass = true, fail;

	try
	{
		{
			char *plain = "Everyone gets Friday off.";
			byte *signature = (byte *)
				"\x05\xfa\x6a\x81\x2f\xc7\xdf\x8b\xf4\xf2\x54\x25\x09\xe0\x3e\x84"
				"\x6e\x11\xb9\xc6\x20\xbe\x20\x09\xef\xb4\x40\xef\xbc\xc6\x69\x21"
				"\x69\x94\xac\x04\xf3\x41\xb5\x7d\x05\x20\x2d\x42\x8f\xb2\xa2\x7b"
				"\x5c\x77\xdf\xd9\xb1\x5b\xfc\x3d\x55\x93\x53\x50\x34\x10\xc1\xe1";
			LC_RNG rng(765);

			FileSource keys("rsa512a.dat", true, new HexDecoder);
			RSASSA_PKCS1v15_MD2_Signer rsaPriv(keys);
			RSASSA_PKCS1v15_MD2_Verifier rsaPub(rsaPriv);

			rsaPriv.SignMessage(rng, (byte *)plain, strlen(plain), out);
			fail = memcmp(signature, out, 64) != 0;
			pass = pass && !fail;

			cout << (fail ? "FAILED    " : "passed    ");
			cout << "signature check against test vector\n";

			fail = !rsaPub.VerifyMessage((byte *)plain, strlen(plain), out);
			pass = pass && !fail;

			cout << (fail ? "FAILED    " : "passed    ");
			cout << "verification check against test vector\n";

			out[10]++;
			fail = rsaPub.VerifyMessage((byte *)plain, strlen(plain), out);
			pass = pass && !fail;

			cout << (fail ? "FAILED    " : "passed    ");
			cout << "invalid signature verification\n";
		}
		{
			FileSource keys("rsa512.dat", true, new HexDecoder);
			RSAES_PKCS1v15_Decryptor rsaPriv(keys);
			RSAES_PKCS1v15_Encryptor rsaPub(rsaPriv);

			pass = CryptoSystemValidate(rsaPriv, rsaPub) && pass;
		}
		{
			byte *plain = (byte *)
				"\x54\x85\x9b\x34\x2c\x49\xea\x2a";
			byte *encrypted = (byte *)
				"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a"
				"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4"
				"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52"
				"\x62\x51";
			byte *oaepSeed = (byte *)
				"\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2"
				"\xf0\x6c\xb5\x8f";
			ByteQueue bq;
			bq.Put(oaepSeed, 20);
			FixedRNG rng(bq);

			FileSource privFile("rsa400pv.dat", true, new HexDecoder);
			FileSource pubFile("rsa400pb.dat", true, new HexDecoder);
			RSAES_OAEP_SHA_Decryptor rsaPriv(privFile);
			RSAES_OAEP_SHA_Encryptor rsaPub(pubFile);

			memset(out, 0, 50);
			memset(outPlain, 0, 8);
			rsaPub.Encrypt(rng, plain, 8, out);
			outLen = rsaPriv.Decrypt(encrypted, outPlain);
			fail = (outLen!=8) || memcmp(out, encrypted, 50) || memcmp(plain, outPlain, 8);
			pass = pass && !fail;

			cout << (fail ? "FAILED    " : "passed    ");
			cout << "PKCS 2.0 encryption and decryption\n";
		}
	}
	catch (BERDecodeErr)
	{
		cout << "FAILED    Error decoding RSA key\n";
		pass = false;
	}

	return pass;
}
예제 #10
0
파일: test.cpp 프로젝트: NotHawthorne/umbra
void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename)
{
	FileSource privFile(privFilename, true, new HexDecoder);
	RSASS<PKCS1v15, SHA>::Signer priv(privFile);
	FileSource f(messageFilename, true, new SignerFilter(GlobalRNG(), priv, new HexEncoder(new FileSink(signatureFilename))));
}