rsa

RSA_private_encrypt always fails

别来无恙 提交于 2020-01-04 18:55:34
问题 I am learning to use OpenSSL library in my program. Here in the code I generate a private key and immediately I am encrypting a message using that key. But always it fails. Kindly help me. private_key = RSA_generate_key(RSA_KEY_LENGTH, RSA_3, NULL, NULL); if (RSA_check_key(private_key) < 1) { printf("generate_key: key generation failed\n"); exit(-1); } unsigned char msg[25]; unsigned char cipher[128]; strcpy((char*)msg, "hello"); int ret = RSA_private_encrypt(25, msg, cipher, private_key, RSA

Decrypt gpg in Java without using Java.Runtime

不羁岁月 提交于 2020-01-04 15:29:11
问题 I have a .gpg file and a RSA private key. How can I programatically decrypt it without using operating system? e.g. without using something like Runtime.getRuntime().exec("gpg -decrypt....."); Libraries I've found all run operating system. Like GnuPG or gnugpg-for-java. 回答1: The Bouncy Castle library provides (among other features) an OpenPGP implementation. The package org.bouncycastle.openpgp.examples contains several usage examples, one of them showing how to encrypt/decrypt a file using a

How to load Base64 RSA keys in Crypto++

微笑、不失礼 提交于 2020-01-04 09:09:28
问题 I'm trying to write helper functions for a program I'm making and I need to return the keys as strings. Found a way to convert the RSA keys from PrivateKey/PublicKey to Base64 string. int main() { //Generate params AutoSeededRandomPool rng; InvertibleRSAFunction params; params.Initialize(rng, 4096); //Generate Keys RSA::PrivateKey privKey(params); RSA::PublicKey pubKey(params); //Encode keys to Base64 string encodedPriv, encodedPub; Base64Encoder privKeySink(new StringSink(encodedPriv));

Crypto++应用:非对称加密RSA

。_饼干妹妹 提交于 2020-01-04 04:02:12
1,非对称加密RSA: (1)乙方生成两把密钥(公钥和私钥)。公钥是公开的,任何人都可以获得,私钥则是保密的。 (2)甲方获取乙方的公钥,然后用它对信息加密。 (3)乙方得到加密后的信息,用私钥解密。 2,使用CryptoPP实现RSA: CryptoPP是一套非常完整的加密解密开源解决方案,如何使用这里就不多说了,请自行Google。 1 #include "..\cryptopp562\randpool.h" 2 #include "..\cryptopp562\osrng.h" 3 #include "..\cryptopp562\rsa.h" 4 5 //待加密的字符串 6 string message = "http://my.oschina.net/xlplbo/blog"; 7 printf("message = %s, length = %d\n", message.c_str(), strlen(message.c_str())); 8 9 /* 10 //自动生成随机数据 11 byte seed[600] = ""; 12 AutoSeededRandomPool rnd; 13 rnd.GenerateBlock(seed, sizeof(seed)); 14 printf("seed = %s\n", (char *)seed, strlen((char

网络安全RSA加密

心不动则不痛 提交于 2020-01-04 03:26:07
网络安全课相关知识: RSA 预备知识 1.1 快速幂算法 顾名思义,快速幂就是快速算底数的$n$次幂。其时间复杂度为${\rm{O(log n)}}$,与朴素的$O\left( n \right)$相比,效率有了极大的提高。具体可以参考百度百科:快速幂。 1.2 扩展欧几里得算法 扩展欧几里得算法(英语:Extended Euclidean algorithm)是欧几里得算法(又叫辗转相除法)的扩展。已知整数a、b,扩展欧几里得算法可以在求得a、b的最大公约数的同时,能找到整数x、y(其中一个很可能是负数),使它们满足贝祖等式 ax+by=gcd(a,b). ax+by=gcd(a,b). 如果$a$是负数,可以把问题转化成 $\left| a \right|\left( { - x} \right){\rm{ }} + {\rm{ }}by{\rm{ }} = {\rm{ }}gcd\left( {\left| a \right|,b} \right)$($\left| a \right|$为a的绝对值),然后令$x\prime {\rm{ }} = {\rm{ }}\left( { - x} \right)$。具体可以参考维基百科:扩展欧几里得。 1.3 米勒-拉宾素性检验算法 要测试${\rm{N}}$是否为素数,首先将${\rm{N - 1}}$分解为${2^s}d$

iPhone/Objective-c RSA encryption

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 21:10:49
问题 I have been Google-ing and researching for an answer on how to do a simple RSA encryption using Cbjective-C on an iPhone. The main problem I have is that I have been supplied the Exponent and Modulus as an NSData object and i need to then convert them to a SecKeyRef object in order to perform the RSA encryption. Does anyone have any idea how to do that or have any useful hints? Many thanks! 回答1: I ended up using OpenSSL in my project. and import the keys and encrypt using that library instead

RSA Encryption in metro style Application

早过忘川 提交于 2020-01-03 18:51:14
问题 I have public key modulus and public key exponent and I need to generate a public key and encrypt data in metro style application. in c# we have RSAParameters class but I cannot find any thing of such sort for metro style applications. when I use the base64encoded public key directly received from the certificate and try to import the key with the below code I get an exception thrown ASN1 bad tag value met. which i think is due to the invalid format of the data. //sample dummy key from

RSA Encryption in metro style Application

梦想与她 提交于 2020-01-03 18:51:14
问题 I have public key modulus and public key exponent and I need to generate a public key and encrypt data in metro style application. in c# we have RSAParameters class but I cannot find any thing of such sort for metro style applications. when I use the base64encoded public key directly received from the certificate and try to import the key with the below code I get an exception thrown ASN1 bad tag value met. which i think is due to the invalid format of the data. //sample dummy key from

Why is RSACryptoServiceProvider.Encrypt() output not stable?

蹲街弑〆低调 提交于 2020-01-03 07:20:12
问题 Until today I was living under the impression that RSA encryption using RSA is deterministic. After all, how should signature verification work if it wasn't? To my big suprise, .NETs RSACryptoServiceProvider does not have a stable output when encrypting the same set of bytes with the same keys: [Fact] public void Learning() { const int keySize = 1024; System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(keySize); var bytes =

Javascript RSA decryption using private key

大城市里の小女人 提交于 2020-01-03 03:12:13
问题 Hello I have this script that I set in Javascript : <!DOCTYPE html> <html lang="en"> <head> <script src="jquery-1.7.2.min.js" type="text/javascript"></script> <script language="JavaScript" type="text/javascript" src="jsbn.js"></script> <script language="JavaScript" type="text/javascript" src="rsa.js"></script> <script language="JavaScript"> function encryptData(){ var pem ="-----BEGIN PUBLIC KEY-----\ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+tii3IwzHa4i142kAB0dRVXoXA2Q8oF48UgMA\ AV54