C++ OPENSSL 中PEM_read_bio_RSAPrivateKey 返回NULL 求教呀 5C

测试程序中的,先调用公钥加密,然后调用私钥解密。公钥加密publi是1,私钥解密publi 是0.
RSA* createRSA(unsigned char*key,int publi)
{
RSA *rsa= NULL;
BIO*keybio;
keybio= BIO_new_mem_buf(key, -1);
if(keybio==NULL)
{
printf("Failed to create key BIO\n");
return 0;
}
size_t nSize = BIO_ctrl_pending(keybio);
if(publi)
{
rsa = PEM_read_bio_RSA_PUBKEY(keybio, &rsa,NULL, NULL);
}
else
{
rsa= PEM_read_bio_RSAPrivateKey(keybio, &rsa,NULL, NULL);
}
if(rsa== NULL)
{
printf("Failed to create RSA\n");
}
return rsa;
}
PEM_read_bio_RSA_PUBKEY 返回值正常
PEM_read_bio_RSAPrivateKey 返回值是NULL
第一次接触,在网上找了很多都没得结果.

1个回答

rsa加密的public key格式有多种,常见的有两种,一种密钥头为‘-----BEGIN RSA PUBLIC KEY-----’,一种开头为‘-----BEGIN PUBLIC KEY-----’,二者分别对应rsa的PKCS#1和PKCS#8格式。
  使用openssl库加载rsa的公钥时,使用的函数也不同。以字符串公钥为例,对PKCS#1格式的密钥加载使用PEM_read_bio_RSAPublicKey()函数,对PKCS#8格式公钥的加载使用PEM_read_bio_RSA_PUBKEY()函数。

也是看其他人碰到的问题。
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
C++ OPENSSL 中PEM_read_bio_RSAPrivateKey 返回NULL 求教呀

测试程序中的,先调用公钥加密,然后调用私钥解密。公钥加密publi是1,私钥解密publi 是0. RSA* createRSA(unsigned char*key,int publi) { RSA *rsa= NULL; BIO*keybio; keybio= BIO_new_mem_buf(key, -1); if(keybio==NULL) { printf("Failed to create key BIO\n"); return 0; } size_t nSize = BIO_ctrl_pending(keybio); if(publi) { rsa = PEM_read_bio_RSA_PUBKEY(keybio, &rsa,NULL, NULL); } else { rsa= PEM_read_bio_RSAPrivateKey(keybio, &rsa,NULL, NULL); } if(rsa== NULL) { printf("Failed to create RSA\n"); } return rsa; } PEM_read_bio_RSA_PUBKEY 返回值正常 PEM_read_bio_RSAPrivateKey 返回值是NULL 第一次接触,在网上找了很多都没得结果.

PEM_read_bio_RSAPrivateKey的返回值为NULL

我是要用OPENSSL编写私钥解密部分,但在使用函数PEM_read_bio_RSAPrivateKey()的返回值为NULL。 以下是我的代码: void rsadecrption(unsigned char cipher[],CString Path) {CFile fc; CFileException e; if(!fc.Open(Path,CFile::modeCreate | CFile::modeWrite|CFile::shareExclusive|CFile::typeBinary,&e)) { //AfxMessageBox("打开fp失败"); return; } EVP_PKEY* evpkey; RSA *rsa=NULL; BIO *key = NULL; unsigned long len; char dir[2048]={NULL}; memcpy(dir,Path,1024); //ques for(int i=0;i<1024;i++) { if(i%2==0) dir[i/2]=dir[i]; } ERR_load_crypto_strings(); //from Internet key = BIO_new(BIO_s_file()); BIO_read_filename(key,dir); rsa = PEM_read_bio_RSAPrivateKey(key, NULL, NULL, NULL); //返回值为NULL BIO_free_all(key); if(rsa==NULL){ printf("unable to read private key!\n"); return; } len = RSA_size( rsa ); unsigned char sign[4096]={NULL}; //int Len=strlen(cipher); int block=1024/256; //int remain=1024%256; for(int i=0;i<block;i++) { if(RSA_private_decrypt(256,sign,cipher,rsa,RSA_PKCS1_PADDING)<=0) return; fc.Write(sign,128); } //fwrite(cipher,strlen(sign),1,fc); fc.Close(); }

使用RSA私钥加密消息(如OpenSSL的RSA_private_encrypt)

<div class="post-text" itemprop="text"> <p>I'm trying to implement <a href="http://docs.opscode.com/api_chef_server.html" rel="nofollow noreferrer">Chef API client</a> in Go, but stuck trying to create correct request header RSA signature. According to <a href="http://docs.opscode.com/api_chef_server.html" rel="nofollow noreferrer">documentation</a>:</p> <blockquote> <p>A canonical header is signed with the private key used by the client machine from which the request is sent, and is also encoded using Base64.</p> </blockquote> <p>The following ruby call to <code>OpenSSL::PKey::RSA.private_encrypt()</code> can be found in <code>mixlib-authentication</code> <a href="https://github.com/opscode/mixlib-authentication/blob/master/lib/mixlib/authentication/signedheaderauth.rb#L94" rel="nofollow noreferrer">gem code</a>, it uses <a href="http://ruby-doc.org/stdlib-1.9.2/libdoc/openssl/rdoc/OpenSSL/PKey/RSA.html#method-i-private_encrypt" rel="nofollow noreferrer">OpenSSL bindings</a>, <code>private_encrypt()</code> method calls <code>RSA_private_encrypt</code> <a href="http://www.openssl.org/docs/crypto/RSA_private_encrypt.html" rel="nofollow noreferrer">openssl function</a>.</p> <p>Unfortunately, I cannot find matching function in Go's standard library; <a href="http://golang.org/pkg/crypto/rsa/" rel="nofollow noreferrer"><code>crypto/rsa</code></a> looks close, but it only implements conventional cryptography methods: encryption with <em>public</em> key, hash signing with <em>private</em> key. OpenSSL's <code>RSA_private_encrypt</code> does the opposite: it encrypts (small) message with private key (akin to creating a signature from message hash).</p> <p>This "signing" can also be achieved with this command:</p> <pre><code>openssl rsautl -sign -inkey path/to/private/key.pem \ -in file/to/encrypt -out encrypted/output </code></pre> <p>Are there any native Go libraries to achieve the same result as OpenSSL's <code>RSA_private_encrypt</code>, or the only way is using Cgo to call this function from OpenSSL library? Maybe I'm missing something. My idea was implementing the client without any non-go dependencies.</p> <p>I'm a Go newbie, so I'm not sure I can dive into <code>crypto/rsa</code> module sources.</p> <hr> <p>Found the <a href="https://stackoverflow.com/questions/3107143/how-do-i-encrypt-with-an-rsa-private-key-read-from-a-pem-file-using-the-go-progr">similar question</a>, but <a href="https://stackoverflow.com/a/3114679/229034">the answer</a> to use <code>SignPKCS1v15</code> is obviously wrong (this <a href="http://golang.org/pkg/crypto/rsa/#SignPKCS1v15" rel="nofollow noreferrer">function encrypts message's hash, not the message itself</a>).</p> </div>

使用openssl_public_encrypt加密的数据每次都不同?

<div class="post-text" itemprop="text"> <p>why is the content of $encrypted every time different? </p> <pre><code>// aquire public key from server $server_public_key = openssl_pkey_get_public(file_get_contents("C:\publickey.pem")); // rsa encrypt openssl_public_encrypt("123", $encrypted, $server_public_key); </code></pre> <hr> <p>also I have tried this one</p> <pre><code>$publicKey = "file://C:/publickey.pem"; $privateKey = "file://C:/privatekey.pem"; $plaintext = "String to encrypt"; openssl_public_encrypt($plaintext, $encrypted, $publicKey); $transfer = base64_encode($encrypted); openssl_private_decrypt($encrypted, $decrypted, $privateKey); echo $transfer; //encrypted string </code></pre> <p>and $transfer is everytime a different string:...</p> <p>Z1xyMUquARxcGjqjjSHNAm41CnHI02GXxLyFivvta8YhDkhRJdD4i3kx+8GElljdiSY/NMF9UD3ritWMLGmscdq/QyIf+geYxJFePNd1dNWg+V6zbAKRLaEpsU+aB87jiM/GjytLEkI63dku02BS0ZBgz9UZw/FDNaynV5bTTDM=</p> <p>mRgLPsPtMoV9la7zzuU+cLzS5xMDp7QUmH6Iv4Sv4/FNjt62zcv9ZMWkfG3uVhS8Z1UDtGl+met1CYjBTcfjHCR6hahbwOkTCICXtkRQcc371vURW04XhQzMNgIIbvN5BBdmIyYI6alrS2vKUq7b3T0h8sJf36zh5CynYzyDCFU=</p> <p>G5FhMoJGiUwEBvEOeZpDDrEXdxbWX5iaJ6F+VdYJ3CURPRMftskZNlDhat8gA5V0G+3nXVQZptkHjxMkOqPlmwJHjgIqAiFppHLpEKohyT9qNwkAR00Y6PiWrNUJPiEIZqXHAb8TS0AA0Quhc0UAwcc+I8NGOD59k8BrZE6Z5Ew=</p> </div>

openssl_pkey_get_public返回false,但密钥确实存在

<div class="post-text" itemprop="text"> <p>I'm using a library that uses openssl_pkey_get_public, but it's returning false. It seems that openssl is enabled, and the key exists. Below are the few lines from the library I'm using, btw which I am debugging but cannot modify as it is not my code base:</p> <pre><code>protected function decrypt($encryptedData) { $publicKey = openssl_pkey_get_public($this-&gt;publicKey-&gt;getKeyPath()); $publicKeyDetails = @openssl_pkey_get_details($publicKey); if ($publicKeyDetails === null) { throw new \LogicException( sprintf('Could not get details of public key: %s', $this-&gt;publicKey-&gt;getKeyPath()) ); } . . . </code></pre> <p>I have the inserted the following debug code:</p> <pre><code>$keyPath = $this-&gt;publicKey-&gt;getKeyPath(); // returns file:///var/www/sso/website/storage/id_rsa.pub var_dump(file_exists($keyPath)); // outputs true var_dump(openssl_pkey_get_public($keyPath)); // returns false </code></pre> <p>Below shows the contents of $keyPath:</p> <pre><code>echo file_get_content($keyPath); ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChY1gtF0Oeku62+4HCisIswcDu9fjZV7fImTlqQej/UsmsJH7jz5EF/ZXCWTKV/bgOwzV2oeHomukITqiR14D01W3mVcpTBAp5AP4JN25am57xdc6Nxd8Lo/NsCKKqQ4/uBmpYBVZm8Ye/hu3ixM6y/xbCGnw/ca4z0DKDa94z1XrRc6FrV1mXx5lItQEo/v8wVKX9NJVAANYZ/jJEk7jGTB9WkSTNR5l/tNBBF3MFuBigjSuaxUsnKT2IwOV5g2ewN4TzXARi2/BI7rweNsUFCWRbkUa7VJc3XOVZbS50TzUpAIqHI9Q8enBs95A1JvSTDvlT3efEHrM2T7KP7QOz ubuntu@ubuntu-xenial </code></pre> <p>I had previously created the keys with the following command:</p> <pre><code>ssh-keygen -f storage/id_rsa -t rsa -N '' </code></pre> <p>Some additional info if it help:</p> <pre><code>$ php -i | grep openssl openssl Openssl default config =&gt; /usr/lib/ssl/openssl.cnf openssl.cafile =&gt; no value =&gt; no value openssl.capath =&gt; no value =&gt; no value $ php -m | grep openssl openssl </code></pre> <p>Is there any reason why this might be happening?</p> </div>

用golang代替load_pem_private_key()

<div class="post-text" itemprop="text"> <p>I have this code in python</p> <pre><code>privateKey = appAuth["privateKey"] passphrase = appAuth["passphrase"] from cryptography.hazmat.primitives.serialization import load_pem_private_key key = load_pem_private_key( data=privateKey.encode('utf8'), password=passphrase.encode('utf8'), backend=default_backend(),) </code></pre> <p>I want to replicate this in golang. Basically I have this:-</p> <pre><code>"appAuth": { "publicKeyID": "2qwqckds", "privateKey": "-----BEGIN ENCRYPTED PRIVATE KEY----- MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0AeQwwDgQIkkci4MFCUtsCAggA MBQGCCqGSIb3DQMHBAjyW3BUgbqg9ASCBMjEpz/mhgRXFKkFpSL4SAq7YLxYzO7H YfbisbcsrN4C1wAiXpT4FMBuGnHzRrm/slu+DnTdbsKrg2SxiyW3Zy5FtBfYGPHF Yim4It2lPywMHHS62b2qXdIicW4pfst/eqeisLpl0bBTR7UYbxr6vpsVFKrGkjEI 8+VtADGgm6ORH975NBZiLrCEO2aLOfeXlQrdWHcNEB46emvoasBKRZ0bUTxUqKN9 egGPprpfEb7yp0UoJZayYpxcZOSEuM42jXiGELQ9qM7xeADlTP5rbw2d6r/Hbr67 vyDk2fydvRra4XlbDgeKfiD71OaetoyF8o07Zo4VJegdZnHYW7BW2kXuD5uCiNYI WN3l9TpX8i6FU1i++NidH80t5cHAHlhBc2v0if5g8TlmRDarOo6pX8d2KLV98V7F 7iWmS9vHtyZZvIgaWDchQ+fVQ2ZS6KCRGnGipxkmGyDXnPcx60YPiN9NxCmKs0ji 8e7xtM+QXzYPWF/rUQh/YmISYGoktOj2XMxXmpNXdpcHFIWEbuW0LuWhV++4WrnO ly9Vc3PwnHi5KE+IzgoOtgPkxDkr664fd5H0DD3RD1ytWuMW0rtKMr8jx/vRUkzM +yzGo0UMe4XW0M0Xcrpq+o+0NBwa05xGA6vlrerMuLcsYG3MexdBkuVMammpmxdM tQ+Ch65ikggn9Er2LbwJyddw7bUaIox0hXPUaiAyICY77D7m4SEsBfMFjy420UoR umz1+ss4edJ0ago0FumG3QaUJzTGUfCHd/johD3AkYAQsFvwiCkMcL2wQEcYDx4x x8OCdM1rTn61sQOHHYH4fN4V8TAEbhG57kSzz/GLBlIu84m7zew+NN3pTTw5oU+V VHFyBj1eW9ywtING1oEnbKXIdzSs4dWF7zwlzDUfbS5GY6Crm7vhre6pnZY0zs3O +MzcGe0AHPwRPOtR4gUiuW5tbBhLM9Nd8xFdS29QUnydKDpSbhySJgCPcYkTtbSG sQZMAK7d/Dv178Qta5a+oO0XMh7I4qZ6tuBlGH06QEUh2NJrfzp42hUS0zd9XIZ5 StD/R9aTSLTr0ljfzrgs/brGj9S0eSHuxV/4teTYapmZoO+G3G7SfViSRn+IdDdK OLa5sLeOu/KCdH0mIyVDupmJKt0adAza3S4Wp719HZVrgOOJc4Ni9GXPiPR5Qxv5 G+/oUIrBxvBpK4gB6Fzr1iRz51FmvukURdeHVDJfbNyEvFWyQ6w5ZXrSbWnD73WB k7/J4N2gLKYVYagI/J9GZ4q/cfM5w+JztdqeBXOKa7fyEBE3iEv5hKs/C7lvxuQs o0yrqTok0GnrlSGq4R0ve/t6eQ4nyWLM1yMxhl/JMGw7QFq7bhfeAhwVcQB7f1eT /krRppgbBwkGHaES47LkoBV9AyZlRIymFaF128SePSSa1YgIaivxghcopdqC3HD1 /NSFA9zvxXv54Neqv9sO2Mc2PHaiOq3RPQbP4zPV7CD8bBSUwztLNAJJC99OeNah 1nyvS69JvysuM7Mxgv3e8VK4+hQ+I1uMwL8UlfCJZ+ejHwpLX26kc7NfKP/NWzm7 6JCsEbbtoR7OWnVgXf0lkIlJPcs86HPoX1DzlzVUQsAtKLpnhxLBBfDH5NwVtolM n74= -----END ENCRYPTED PRIVATE KEY----- ", "passphrase": "2788518b2900d77fafc71dbf4f764927" } </code></pre> <p>In golang, I have tried this so far:-</p> <pre><code>block, _ := pem.Decode([]byte(privateKey)) \\ privateKey is a string key, err := x509.ParsePKCS1PrivateKey(block.Bytes) </code></pre> <p>But it doesn't work. Please Help.</p> </div>

openssl_private_decrypt()返回false

openssl_private_decrypt()函数一直返回false

如何从文件读取RSA密钥

<div class="post-text" itemprop="text"> <p>I need to read in an RSA private key from a file to sign a JWT. I have found some examples on how to save a generated RSA key to disk but nothing showing how to build a key struct based on a pre-generated key from a file.</p> <p>The key is generated like this:</p> <pre> openssl genrsa 2048 | openssl pkcs8 -topk8 -nocrypt </pre> <p>Example key:</p> <pre> -----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQClHYNDPVSF‌​FmWF oKGTqd/n7Dt2+tGXh97KJjVLAqCBZZHlQJ534v2OzFjTgzuMNehD9Y6HnkYF‌​dkRb QzYi2YDROOzRl1bhyyWPA35OGf50r7LiNvSvNPNtswsCuK7ywOcH0yEMKSiW‌​4q5R GKYi42w961EcTQQPrfihavY+c2FYPv4+pXymzaIz9hGBPLHwaHq/QTAyHxPC‌​fkOo s/x3mxUVd7Ni2bz1VJGlyqcNEeU88wTAYMmv8oQ3y2NfKExtYn+W6TCDiq/+‌​ZkOp wacuAU0J7tCNgcXvkq39KH5uza2uSiTniye6uhlkvYWD3s9riIIiekTEiHk/‌​kkc6 jMg8HN/7AgMBAAECggEBAJ12u8vQHV6esUrymaTdCG+BVmRtZpyA ... -----END RSA PRIVATE KEY----- </pre> </div>

在golang中将RSA PrivateKey PEM写入文件

<div class="post-text" itemprop="text"> <p>I'm using <a href="https://godoc.org/github.com/spacemonkeygo/openssl" rel="nofollow">spacemonkeygo's openssl library</a> to generate an RSA PrivateKey - the library also offers ways to load a private key from a PEM, but I can't figure out how to turn the private key into an encrypted PEM block - anyone got any ideas?</p> <pre><code>import "github.com/spacemonkeygo/openssl" // Generate a private key privateKey, _ := openssl.GenerateRSAKey(2048) password := "an encryption password" // Create an encrypted PEM block from the private key? pem := ??? // Load the PEM file loadedPrivateKey, _ := openssl.LoadPrivateKeyFromPEMWidthPassword(pem, password) privateKey == loadedPrivateKey </code></pre> </div>

openssl_pkcs12_read失败

<div class="post-text" itemprop="text"> <p>I am trying to read a p12 formatted certificate file with php function <code>openssl_pkcs12_read</code>. My code looks like this:</p> <pre><code>&lt;?php $fname = "./client-cert.p12"; $handle = fopen($fname, "r") or die ("Unable to open file!"); $p12buf = fread($handle, filesize($fname)); fclose($handle); $certs = array(); $pass = "bliblablup"; $result = openssl_pkcs12_read($p12buf, $certs, $pass); if ( $result ) { print_r( $certs ); } else { print_r( "Error! "); } </code></pre> <p>I am always running into the error-branch of <code>if($result) ...</code> and cannot find any information how to get more details on the error condition. Any hints welcome.</p> </div>

如何修复PHP中的openssl_private_decrypt()错误?

<div class="post-text" itemprop="text"> <p>I need finish this part of school project.</p> <p><strong>Create openssl public and private key</strong></p> <pre><code>function openssl($text){ # privaten Schlüssel erzeugen $res=openssl_pkey_new(); # privaten Schlüssel zu String openssl_pkey_export($res, $privatekey); # öffentlichen Schlüssel $publickey=openssl_pkey_get_details($res); $publickey=$publickey["key"]; openssl_public_encrypt($text, $crypttext, $publickey); $filenameCrypttext = "crypttext.txt"; $filenamePrivatekeyText = "privatekey.txt"; $files = [$filenameCrypttext, $filenamePrivatekeyText]; createFile($crypttext, $filenameCrypttext); createFile($privatekey,$filenamePrivatekeyText); downloadZip($files); } function createFile($crypttext, $filename){ file_put_contents($filename, $crypttext.PHP_EOL , FILE_APPEND | LOCK_EX); } function downloadZip($files){ $zipname = "packet.zip"; $zip = new ZipArchive; $zip-&gt;open($zipname, ZipArchive::CREATE); foreach ($files as $file){ $zip-&gt;addFile($file); } $zip-&gt;close(); foreach ($files as $file) { unlink($file); } header("Location: download.php?filename=$zipname"); } </code></pre> <p>I download my 2 files <em>crypttext.txt</em> and <em>privatekey.txt</em> as zip. Later I want to upload them.</p> <p><a href="https://pastebin.com/LAvGLdFf" rel="nofollow noreferrer"><strong>Encrypted</strong></a></p> <p><a href="https://pastebin.com/0awFyxQx" rel="nofollow noreferrer"><strong>Privatekey</strong></a></p> <p><strong>And the following code is my decryption function</strong></p> <pre><code>&lt;div class="container"&gt; &lt;br&gt; &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt; &lt;label&gt;Encrypted Text&lt;/label&gt; &lt;textarea name="encrypted_text" placeholder="Text einfügen" class="form-control" rows="3"&gt;&lt;/textarea&gt; &lt;label&gt;Private Key &lt;/label&gt; &lt;textarea name="private_key" placeholder="Text einfügen" class="form-control" rows="3"&gt;&lt;/textarea&gt; &lt;br&gt; &lt;button type="submit" class="btn btn-primary"&gt;Hochladen&lt;/button&gt; &lt;/form&gt; &lt;?php if(isset($_POST['encrypted_text'], $_POST['private_key'])){ echo 'isset'; $encrypted = $_POST['encrypted_text']; $privatekey = $_POST['private_key']; $res = openssl_get_privatekey($privatekey); openssl_private_decrypt($encrypted, $decrypted, $res); echo '&lt;br&gt;'; echo $decrypted; echo '&lt;br&gt;'; } ?&gt; </code></pre> <p></p> <p>I dont get a result. Where is my misstake?</p> </div>

Golang中有与PHP openssl_pkey_get_private等效的东西吗?

<div class="post-text" itemprop="text"> <p>I have to translate PHP code to Golang and I encoutered this problem.</p> </div>

openssl移植到armBN_mod_inverse:no inverse

Openssl RSA编程代码在pc机上可以正常运行。 交叉编译到ARM 上会有错误, 错误信息error:0306E06C:bignum routines:BN_mod_inverse:no inverse。求大神指教。 ``RSA *rsa = NULL; BIO *bio = NULL; int rsa_len = 0; int num = 0; if ((bio = BIO_new_mem_buf((void *)PubKeyAuth, -1)) == NULL) { return RSA_ENCRYPT_ERROR; } if ((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)) == NULL) { return RSA_ENCRYPT_ERROR; } BIO_free_all(bio); rsa_len = RSA_size(rsa); num = RSA_public_encrypt(rsa_len, (unsigned char *)str, (unsigned char *)SendMessageBuff, rsa, RSA_PKCS1_PADDING ); if (num < 0) { return RSA_ENCRYPT_ERROR; } RSA_free(rsa); return num;` ```

openssl_public_encrypt和JSON

<div class="post-text" itemprop="text"> <p>Let's say we need to store in a crypted way some confidential data into a db. And say that we need them into <code>json</code> format as will be more suitable for data reconstruction.</p> <p>There's something that I miss that is driving me crazy.</p> <p>Take that json for instance</p> <pre><code>$json = {"customer":{"customer_address":"Fake address 123","customer_city":"Fake City","customer_company":"","customer_countrycode":"it","customer_email":"","customer_telephone":"+39.347.xxxxxxx","customer_zip":"yyyyy"},"currency_code":"EUR","commision_amount":"84"} </code></pre> <p>now I want to crypt this <code>json</code> and I do the following</p> <pre><code>$pubKey = openssl_pkey_get_public($puk); openssl_public_encrypt($json, $json_crypted, $pubKey); </code></pre> <p>if I <code>echo $json_crypted</code> it doesn't show anything, but if I remove some field (like <code>customer_company</code>, that is empty) all seems to work. I've tried to find something into documentation about this strange behaviour but I can't find anything.</p> <p>Is someone aware of the reason behind that result?</p> <h2>Edit</h2> <p>Even if I remove other field (not an empty one) all seems to work. I'm speechless because it has to be a silly thing that I can't understand</p> </div>

php创建证书签名请求到文件错误/警告

<div class="post-text" itemprop="text"> <p>I need to create a certificate signing request to file but last line give error when run:</p> <pre><code>Warning: openssl_csr_export_to_file() expects parameter 1 to be resource, boolean given </code></pre> <p>Any idea? this is the code, it's php 7.04 - wamp. </p> <pre><code> &lt;?php $subject = array( "commonName" =&gt; "example.com", ); $private_key = openssl_pkey_new(array( "config" =&gt; "C:/wamp/bin/php/php7.0.4/extras/ssl/openssl.cnf", "private_key_bits" =&gt; 2048, "private_key_type" =&gt; OPENSSL_KEYTYPE_RSA )); $csr = openssl_csr_new($subject, $private_key, array('digest_alg' =&gt; 'sha384') ); openssl_pkey_export_to_file($private_key, 'example-priv.key'); // Along with the subject, the CSR contains the public key corresponding to // the private key openssl_csr_export_to_file($csr, 'example-csr.pem'); </code></pre> </div>

python 关于 OpenSSL.crypto 模块验签问题

对接一个接口,在数据发送与接收时需要rsa签名和验签。 采用 OpenSSL.crypto 模块进行签名 签名的主要部分是: ``` from OpenSSL.crypto import load_privatekey,FILETYPE_PEM,sign,verify def tosign(data,private_key): key = load_privatekey(FILETYPE_PEM, private_key) return base64.b64encode(sign(key,data,'sha1')) def verysign(data,getsign,public_key): sign = base64.b64decode(getsign) key = load_certificate(FILETYPE_PEM,public_key) ret = verify(key,sign,data,'sha1') return ret ``` 密钥是”BEGIN RSA PRIVATE KEY --- END RSA PRIVATE KEY” 公钥是 “ BEGIN PUBLIC KEY --- END PUBLIC KEY” 签名是没有问题的,但是验签会报错:[('PEM routines', 'PEM_read_bio', 'no start line')] 对一些加密解密加签的本来就不熟,在 google 后更加蒙蔽了,所以想请问各位大佬指出一下问题,给个解决方案或者一点建议

C使用openssl RSA base64对数据进行加密解密出错

对数据进行RSA base64加密的时候没有出错,但是在解码base64的时候解码出来的字符串为空。 附代码,求大佬帮忙看一下: ``` int base64_encode(char *in_str, int in_len, char *out_str) { BIO *b64, *bio; BUF_MEM *bptr = NULL; size_t size = 0; if (in_str == NULL || out_str == NULL) return -1; b64 = BIO_new(BIO_f_base64()); bio = BIO_new(BIO_s_mem()); bio = BIO_push(b64, bio); BIO_write(bio, in_str, in_len); BIO_flush(bio); BIO_get_mem_ptr(bio, &bptr); memcpy(out_str, bptr->data, bptr->length); out_str[bptr->length] = '\0'; size = bptr->length; BIO_free_all(bio); return size; } ``` ``` int base64_decode(char *in_str, int in_len, char *out_str) { BIO *b64, *bio; BUF_MEM *bptr = NULL; int counts; int size = 0; if (in_str == NULL || out_str == NULL) return -1; b64 = BIO_new(BIO_f_base64()); BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); bio = BIO_new_mem_buf(in_str, in_len); bio = BIO_push(b64, bio); size = BIO_read(bio, out_str, in_len); out_str[size] = '\0'; BIO_free_all(bio); return size; } ``` ``` unsigned char *my_encrypt(char *str,char *path_key){ char *p_en; RSA *p_rsa; FILE *file,*p_file; int flen,rsa_len; if((file=fopen(path_key,"r"))==NULL){ perror("open key file error"); return NULL; } if((p_rsa=PEM_read_RSA_PUBKEY(file,NULL,NULL,NULL))==NULL){//PUBLIC KEY // if((p_rsa=PEM_read_RSAPublicKey(file,NULL,NULL,NULL))==NULL){//RSA PUBLIC KEY ERR_print_errors_fp(stdout); return NULL; } flen=strlen(str); rsa_len=RSA_size(p_rsa); p_en=(unsigned char *)malloc(rsa_len+1); memset(p_en,0,rsa_len+1); if(RSA_public_encrypt(rsa_len,(unsigned char *)str,(unsigned char*)p_en,p_rsa,RSA_NO_PADDING)<0){ return NULL; } RSA_free(p_rsa); fclose(file); // p_file=fopen("./p_file.txt","w"); // fputs(p_en, p_file); return p_en; } ``` ``` char *my_decrypt(unsigned char *str,char *path_key){ char *p_de; RSA *p_rsa; FILE *file; int rsa_len; if((file=fopen(path_key,"r"))==NULL){ perror("open key file error"); return NULL; } if((p_rsa=PEM_read_RSAPrivateKey(file,NULL,NULL,NULL))==NULL){ ERR_print_errors_fp(stdout); return NULL; } rsa_len=RSA_size(p_rsa); p_de=(unsigned char *)malloc(rsa_len+1); memset(p_de,0,rsa_len+1); if(RSA_private_decrypt(rsa_len,(unsigned char *)str,(unsigned char*)p_de,p_rsa,RSA_NO_PADDING)<0){ return NULL; } RSA_free(p_rsa); fclose(file); return p_de; } ``` ``` main{ char source[1024]="hello"; char *ptr_en,*ptr_de, base64_en[1024] = "", base64_de[1024] = ""; printf("source is    :%s\n",source); ptr_en=my_encrypt(source,PUBLICKEY); printf("ptr_en strlen = %d\n", strlen(ptr_en)); printf("after encrypt:%s\n",ptr_en); base64_encode(ptr_en,strlen(ptr_en),base64_en); printf("after encode len: %d\nmsg:%s\n",strlen(base64_en), base64_en); base64_decode(base64_en,strlen(base64_en),base64_de); printf("after decode len: %d\nmsg:%s\n",strlen(base64_de), base64_de);//len输出长度为0 数据为空 ptr_de=my_decrypt(base64_de,OPENSSLKEY); printf("ptr_de strlen = %d\n", strlen(ptr_de)); printf("after decrypt:%s\n",ptr_de); if(ptr_en!=NULL){ free(ptr_en); } if(ptr_de!=NULL){ free(ptr_de); } return 0; } ``` base64_decode解码后长度为0,数据为空。当他们单独使用的加密解密的时候没问题,合起来就会出现这个情况,求大佬看一下 ,非常感谢

有全部源码,我调用openssl库的RSA和AES算法进行加密。加密字符串太长就会报错,具体如下。

报错信息是这样的: Error encrypting message: error:0406D06E:rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size Error decrypting message: error:0407106B:rsa routines:RSA_padding_check_PKCS1_type_2:block type is not 02 我用的Linux环境进行开发的,不过也应该没有太大关系啦! 另外代码上有什么问题也可以指出来,万分感谢!!! 具体代码 如下: ``` #include <openssl/rsa.h> #include <openssl/sha.h> #include <openssl/ssl.h> #include <openssl/aes.h> #include <openssl/evp.h> #include <openssl/pem.h> #include <openssl/err.h> #include <assert.h> #include <iostream> #include <string.h> #include <stdio.h> #include <string> #include <stdlib.h> #define RSA_KEYLEN 2048 #define AES_KEYLEN 128 #define AES_ROUNDS 6 #define KEY_SERVER_PRI 0 #define KEY_SERVER_PUB 1 #define KEY_CLIENT_PUB 2 #define KEY_AES 3 #define KEY_AES_IV 4 #define KEY_LENGTH 2048 #define PUB_EXP 3 //用AES进行加密 int EncodeAES(unsigned char* password,unsigned int pass_len, unsigned char* data,unsigned int data_len,unsigned char** out_data,unsigned int *out_len) { AES_KEY aes_key; if(AES_set_encrypt_key((const unsigned char*)password, 192, &aes_key) < 0) { assert(false); return -1; } std::string strRet; std::string data_bak((const char*)data); unsigned int data_length = data_len; int padding = 0; if (data_len % AES_BLOCK_SIZE > 0) { padding = AES_BLOCK_SIZE - data_len % AES_BLOCK_SIZE; } data_length += padding; while (padding > 0) { data_bak += '\0'; padding--; } for(unsigned int i = 0; i < data_length/AES_BLOCK_SIZE; i++) { std::string str16 = data_bak.substr(i*AES_BLOCK_SIZE, AES_BLOCK_SIZE); unsigned char out[AES_BLOCK_SIZE]; ::memset(out, 0, AES_BLOCK_SIZE); AES_encrypt((const unsigned char*)str16.c_str(), out, &aes_key); strRet += std::string((const char*)out, AES_BLOCK_SIZE); } *out_len=strRet.length(); *out_data=(unsigned char*)malloc(*out_len); *out_data=(unsigned char*)strRet.c_str(); return 0; } //用aes进行解密 int DecodeAES(unsigned char *password,unsigned int pass_len, unsigned char* data,unsigned int data_len,unsigned char** out_data,unsigned int *out_len ) { AES_KEY aes_key; if(AES_set_decrypt_key((const unsigned char*)password, 192, &aes_key) < 0) { assert(false); return -1; } std::string strRet; std::string strData((const char*)data); try { for(unsigned int i = 0; i < data_len/AES_BLOCK_SIZE; i++) { std::string str16 = strData.substr(i*AES_BLOCK_SIZE, AES_BLOCK_SIZE); unsigned char out[AES_BLOCK_SIZE]; ::memset(out, 0, AES_BLOCK_SIZE); AES_decrypt((const unsigned char*)str16.c_str(), out, &aes_key); strRet += std::string((const char*)out, AES_BLOCK_SIZE); } } catch (std::exception const &exc) { std::cerr << "Exception caught " << exc.what() << "\n"; } catch (...) { std::cerr << "Unknown exception caught\n"; } *out_len=strRet.length(); *out_data=(unsigned char*)malloc(*out_len); *out_data=(unsigned char*)strRet.c_str(); return 0; } //生成RSA需要的公钥和私钥 int generateRSAKeys(char ** pri_key, char ** pub_key) { RSA *keypair = RSA_generate_key(KEY_LENGTH, PUB_EXP, NULL, NULL); // To get the C-string PEM form: BIO *pri = BIO_new(BIO_s_mem()); BIO *pub = BIO_new(BIO_s_mem()); PEM_write_bio_RSAPrivateKey(pri, keypair, NULL, NULL, 0, NULL, NULL); PEM_write_bio_RSAPublicKey(pub, keypair); size_t pri_len = BIO_pending(pri); size_t pub_len = BIO_pending(pub); char* prikey = (char*)malloc(pri_len + 1); char* pubkey = (char*)malloc(pub_len + 1); if (prikey == NULL&&pubkey == NULL) { return -1; } BIO_read(pri, prikey, pri_len); BIO_read(pub, pubkey, pub_len); *pri_key = prikey; *pub_key = pubkey; RSA_free(keypair); BIO_free_all(pri); BIO_free_all(pub); return 0; } //用RSA公钥进行加密 int encryptWithPub(char *pub_key,char* msg, char **encrypt, int* encrypt_len ) { RSA *rsa = NULL; BIO* keybio = BIO_new_mem_buf((void *)pub_key, -1); char *err = (char*)malloc(130); if (keybio == NULL) { printf("failed to create key BIO\n"); return -1; } #ifdef RSAPUBKEY if ((rsa = PEM_read_bio_RSA_PUBKEY(keybio, NULL, NULL, NULL)) == NULL) #else if ((rsa = PEM_read_bio_RSAPublicKey(keybio, NULL, NULL, NULL)) == NULL) #endif if (!rsa){ printf(" rsa is null %s\n", ERR_error_string(ERR_get_error(), NULL)); return -1; } *encrypt_len = RSA_size(rsa); *encrypt = (char *)malloc(1024); if ((RSA_public_encrypt(strlen(msg) + 1, (unsigned char*)msg, (unsigned char*)*encrypt,rsa, RSA_PKCS1_PADDING)) == -1) { ERR_load_crypto_strings(); ERR_error_string(ERR_get_error(), err); fprintf(stderr, "Error encrypting message: %s\n", err); return -1; } RSA_free(rsa); free(err); BIO_free_all(keybio); // *encrypt_len=enstr.length(); return 0; } //用RSA私钥进行解密 int decryptWtihPri(char *pri_key,char* msg,char **decrypt, int encrypt_len){ RSA *rsa = NULL; BIO* keybio = BIO_new_mem_buf(pri_key, -1); if (keybio == NULL) { printf("failed to create key BIO\n"); return -1; } #ifdef RSAPRIVATE if ((rsa = PEM_read_bio_RSA_PRIVATE(keybio, NULL, NULL, NULL)) == NULL) #else if ((rsa = PEM_read_bio_RSAPrivateKey(keybio, NULL, NULL, NULL)) == NULL) #endif if (!rsa){ printf(" rsa null %s\n", ERR_error_string(ERR_get_error(), NULL)); return -1; } char *err = (char*)malloc(130); *decrypt = (char*)malloc(encrypt_len); if (RSA_private_decrypt(encrypt_len, (unsigned char*)msg, (unsigned char*)*decrypt, rsa, RSA_PKCS1_PADDING) == -1) { ERR_load_crypto_strings(); ERR_error_string(ERR_get_error(), err); fprintf(stderr, "Error decrypting message: %s\n", err); return -1; } RSA_free(rsa); free(err); BIO_free_all(keybio); return 0; } /** *测试函数部分 */ int test_aes(); int test_rsa(); int main() { test_rsa(); test_aes(); return 0; } int test_rsa() { printf("\n----------THE RSA TESTING -------- \n"); char * pri_key; char * pub_key; generateRSAKeys(&pri_key, &pub_key); //printf("\n%s\n%s\n", pri_key, pub_key); char *encrypt; char *decrypt; int encrypt_length; encryptWithPub(pub_key,(char *)"i havei have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a key a key",&encrypt, &encrypt_length); decryptWtihPri( pri_key,encrypt, &decrypt,encrypt_length); printf("decrypted message: %s\n", decrypt); return 0; } int test_aes() { printf("\n----------THE AES TESTING --------\n"); char* pass=(char*)"key"; int ret; char* data=(char*)"infocoei have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a key ei have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a key re big tree "; char *output=NULL; unsigned int out_len; char *newoutput=NULL; unsigned int new_len; std::cout<<"the length of key:"<<strlen(pass)<<std::endl; std::cout<<"before encryption:"<<data<<std::endl; ret=EncodeAES((unsigned char*)pass, strlen(pass),(unsigned char *)data,strlen(data),(unsigned char **)&output, &out_len); //std::cout<<"the en len:"<<out_len<<std::endl; ret=DecodeAES((unsigned char*)pass, strlen(pass),(unsigned char *)output,out_len,(unsigned char **)&newoutput, &new_len); //std::cout<<"the deenc len:"<<new_len<<std::endl; std::cout<<"after decryption:"<<newoutput<<std::endl; } ``` 代码的运行结果如下: ``` ----------THE RSA TESTING -------- Error encrypting message: error:0406D06E:rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size Error decrypting message: error:0407106B:rsa routines:RSA_padding_check_PKCS1_type_2:block type is not 02 decrypted message: 惙l= ----------THE AES TESTING -------- the length of key:3 before encryption:infocoei have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a key ei have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a keyi have a key re big tree Exception caught basic_string::substr after decryption:Ϝż§§<¾yK*. [root@localhost boost_encryption]# ``` 我的邮箱是fubohuauser@163.com 有啥问题也可以一起联系交流。谢谢

C++ 用openssl RSA 私钥解密

微信企业号,聊天记录提取:需要提供一个公钥给微信,他们用公钥加密聊天记录,然后我们再用私钥进行解密聊天保存。 用http://tool.chacuo.net/cryptrsapubkey这个网站生成了一对2048为的RSA密钥对,密钥格式为PKCS1。 公钥如下: -----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxGzyp9l2CbGYVu8+8T9c XAnjNB7KCun6fH2j1u/8if29GxeJz/uU73lcIgewJN1z3gfZT29xoPSM3hlvoDG8 e4Kv20BWP63wr8cS5qwEuIno2IOwnhq0Mq09kylDdX9NwVnobLd110q34lN9iNzr 0csWzX07rYDWso4iuUuOTgXKxyQS34/Azgaea88hQLnCCw9YB2ocs1W0lSjhq5Gn k5FZZEhMe5UwaZI2ZgdKrBqSVQvMOxB57eBb6ofLPoDyx8DEkJmz4I6b61P/S7ZL x+Kz7nMCik/OGsJu4Cyr5CEebWyNuZzu9JyhfFc2aGGHda6Ph2/SpVjC15wGDnQL AwIDAQAB -----END PUBLIC KEY----- 加密字符串如下: bESlD7OobKjYMww9swtL6zmWvXl4mrraUt/XJvQpVbpK5u8rUP25/PJDOZms+3LF/3L2sXKj5QjUDPvQbi1ZvLBHB7fcUF59qAILIuOBi8NEgVrw6lx4CClhQciDK9FedcEkRIx/T0zuPiSNJmOyUAhYaJRG2/Xh5Mn+oMJ2LPohq5QWbd9eq17eKdY9LDKmcyoMGqCEt1iBPd1KXqHOsd79ca8aHwXdVH+mrYhHJYT5gZYwylX7LloXRevbFhFxSrFFpDNRRaSuW9vecwwO5EhUun1KoxTB3MYR3cLGowyJ+LFT1iQczr/TFW7EW1egFfeAmy9v6q8ae7blnARedw== 私钥如下: -----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAxGzyp9l2CbGYVu8+8T9cXAnjNB7KCun6fH2j1u/8if29GxeJ z/uU73lcIgewJN1z3gfZT29xoPSM3hlvoDG8e4Kv20BWP63wr8cS5qwEuIno2IOw nhq0Mq09kylDdX9NwVnobLd110q34lN9iNzr0csWzX07rYDWso4iuUuOTgXKxyQS 34/Azgaea88hQLnCCw9YB2ocs1W0lSjhq5Gnk5FZZEhMe5UwaZI2ZgdKrBqSVQvM OxB57eBb6ofLPoDyx8DEkJmz4I6b61P/S7ZLx+Kz7nMCik/OGsJu4Cyr5CEebWyN uZzu9JyhfFc2aGGHda6Ph2/SpVjC15wGDnQLAwIDAQABAoIBAQC5cy8qf+qsvkrZ ESp49NxLXV5wj/0rjrranHh6brwcwD6xfGi1v45fBlKRIncQZzCE2R43nD1IvHrf Gl7EfRC5/6nus/B6UMvj+W0D8jbG0BXRjYvLyeSF0ABJl3TEUzvjJ/KD6jZM3JN+ EFt+Qy42NatCuVEFv5V0oTNxhD9HsxC+hNvOQYUyIXNoSjXQA3VNgPrBavWpLX9d 2lwWxabu2/TcqDdhv0fB035RBNEDNzfWHmmlgfqaFDGlS+lbg6+ym46YuyX5axiw Im0xLuk8RpJ+cP2s56A4PKKwnReAdxWsJqZLeAqQ2hdepTc2TXslq9FUu/btg37f nGqcpazpAoGBAPeKLsmXE9SbL6ZqdgWOT0bY9SiFSMc4P21xB9VkoHuA71881ymt +jZSfyQyXSr1NM/bDStx4n9WmFoIfD2lstIGkURrieoaKb2SCuzQLJOIcsBV12Zz Gk+JrRxgfPqow9x/G3BVnoYird69zEo279CI0xaIYW2fZbEv7vnihmBXAoGBAMsj jEyPOTnv6TAChDLR3fy0NYhU+vBSSreDz6ZGFSO6zyRS419wzjQrjr6w4bFcvkBt 4R8M8Wx/KlXS+oiMK2IrX9QQ6eloMJrUe8lp/a4n7fbo/JsYD10lRa8v9LQGxY5X 1ck/k0J1cW4zyg4vBE7gv1N58Gu2HfrunTq8yw81AoGBAJMH+dh1qyq6bqgrTiTo rYAIeD30RRFIAKyx2ZRPq98P656nFapFE3zWrXxDigFtGkxn8T+f6of2WJIJvjoj xL5pdjmsooNxvN9D8sdMs12CS56gnkvVDIi33yIe0b1VJtk+in7D7GACE0JdfA2M 6g70ZmVY5n3lktKXBRxaB7ULAoGAKOMLzzEYvJ+cWOx4vV3eh4miKMGqDIsTvOJL /lSm1p04KkCAwWoMJxYJUjp6At/+7yrun/hT85mY5NNlV+yWotjGHgIVgsRU3CUe kUjDJbWlwQfeKD1sgjwJTZyibUXbp63oOuyP8FWBMkQ8TCSMgm/cMqodiSCL4kD6 5qKvYG0CgYEAj/v1QKuEEfm1YkkgDtiD68Eq0HDl58n6VS+GM8HLPQb/nUpdFN4z MDHY4cWb+Bt2M2csOcvx2N2Xsl3a/G0Q05q6OCmw/utCGdlHxo+ROPKZssIRYgO/ 67TdgZsRggEa66U2wSIoxBmfsD/qy42k9cYdl1rarTryuU2iJm2/+Ms= -----END RSA PRIVATE KEY----- 我利用openssl库进行解密,代码如下: // 私钥解密,cipherText--待解密字符串; priKey--私钥 std::string rsa_pri_decrypt(const std::string &cipherText, const std::string &priKey) { std::string strRet; RSA *rsa = RSA_new(); BIO *keybio; keybio = BIO_new_mem_buf((void *)priKey.c_str(), -1); // 读取私钥成RSA rsa = PEM_read_bio_RSAPrivateKey(keybio, &rsa, NULL, NULL); // 分配大小 int len = RSA_size(rsa); char *decryptedText = (char *)malloc(len + 1); memset(decryptedText, 0, len + 1); // 解密函数 int ret = RSA_private_decrypt(cipherText.length(), (const unsigned char*)cipherText.c_str(), (unsigned char*)decryptedText, rsa, RSA_PKCS1_PADDING); unsigned long error = ERR_peek_last_error(); if (ret >= 0) strRet = std::string(decryptedText, ret); // 释放内存 free(decryptedText); BIO_free_all(keybio); RSA_free(rsa); return strRet; } 得到的解密结果是解密失败,请问是哪里需要调整?

PHP:致命错误:调用未定义的函数openssl_pkcs12_read()

<div class="post-text" itemprop="text"> <p>I'm using PHP to read encryted file using opensll.</p> <p>when doing </p> <pre><code>openssl_pkcs12_read($storedfile, $certificateinfo, $passwd) </code></pre> <p>in my script, error came out is :</p> <blockquote> <p>Fatal error: Call to undefined function openssl_pkcs12_read()</p> </blockquote> <p>I'm trying to install <code>openssl</code> <code>extension</code> for my Suse Linux Enterprise Server 11. </p> <p>Can anybody help me how to install <code>openssl extension</code> in SLES. or how to solve this problem.</p> <p>thanks</p> </div>

学Python后到底能干什么?网友:我太难了

感觉全世界营销文都在推Python,但是找不到工作的话,又有哪个机构会站出来给我推荐工作? 笔者冷静分析多方数据,想跟大家说:关于超越老牌霸主Java,过去几年间Python一直都被寄予厚望。但是事实是虽然上升趋势,但是国内环境下,一时间是无法马上就超越Java的,也可以换句话说:超越Java只是时间问题罢。 太嚣张了会Python的人!找工作拿高薪这么简单? https://edu....

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

为什么程序猿都不愿意去外包?

分享外包的组织架构,盈利模式,亲身经历,以及根据一些外包朋友的反馈,写了这篇文章 ,希望对正在找工作的老铁有所帮助

Java校招入职华为,半年后我跑路了

何来 我,一个双非本科弟弟,有幸在 19 届的秋招中得到前东家华为(以下简称 hw)的赏识,当时秋招签订就业协议,说是入了某 java bg,之后一系列组织架构调整原因等等让人无法理解的神操作,最终毕业前夕,被通知调往其他 bg 做嵌入式开发(纯 C 语言)。 由于已至于校招末尾,之前拿到的其他 offer 又无法再收回,一时感到无力回天,只得默默接受。 毕业后,直接入职开始了嵌入式苦旅,由于从未...

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

@程序员:GitHub这个项目快薅羊毛

今天下午在朋友圈看到很多人都在发github的羊毛,一时没明白是怎么回事。 后来上百度搜索了一下,原来真有这回事,毕竟资源主义的羊毛不少啊,1000刀刷爆了朋友圈!不知道你们的朋友圈有没有看到类似的消息。 这到底是啥情况? 微软开发者平台GitHub 的一个区块链项目 Handshake ,搞了一个招募新会员的活动,面向GitHub 上前 25万名开发者派送 4,246.99 HNS币,大约价...

用python打开电脑摄像头,并把图像传回qq邮箱【Pyinstaller打包】

前言: 如何悄悄的打开朋友的摄像头,看看她最近过的怎么样,嘿嘿!这次让我带你们来实现这个功能。 注: 这个程序仅限在朋友之间开玩笑,别去搞什么违法的事情哦。 代码 发送邮件 使用python内置的email模块即可完成。导入相应的代码封装为一个send函数,顺便导入需要导入的包 注: 下面的代码有三处要修改的地方,两处写的qq邮箱地址,还有一处写的qq邮箱授权码,不知道qq邮箱授权码的可以去百度一...

C++(继承):19---虚基类与虚继承(virtual)

一、菱形继承 在介绍虚继承之前介绍一下菱形继承 概念:A作为基类,B和C都继承与A。最后一个类D又继承于B和C,这样形式的继承称为菱形继承 菱形继承的缺点: 数据冗余:在D中会保存两份A的内容 访问不明确(二义性):因为D不知道是以B为中介去访问A还是以C为中介去访问A,因此在访问某些成员的时候会发生二义性 缺点的解决: 数据冗余:通过下面“虚继承”技术来解决(见下) 访问...

计算机网络——浅析网络层

一、前言 注意,关于ipv4和ipv6,ipv4是ip协议第4版本,也表示这个版本的ip一共4个字节,同样地,ipv6是ip协议第6版本,也表示这个版本的ip一共6个字节。 关于网络层使用路由器实现互联:在计算机网络的分层结构中,不同层有不同的中继设备: 计算机网络层 中继设备/中继系统 物理层 中继器、集线器Hub 数据链路层 网桥或交换机(交换机是多端口网桥,两者本质上是一个东西) 网络层 路...

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

华为初面+综合面试(Java技术面)附上面试题

华为面试整体流程大致分为笔试,性格测试,面试,综合面试,回学校等结果。笔试来说,华为的难度较中等,选择题难度和网易腾讯差不多。最后的代码题,相比下来就简单很多,一共3道题目,前2题很容易就AC,题目已经记不太清楚,不过难度确实不大。最后一题最后提交的代码过了75%的样例,一直没有发现剩下的25%可能存在什么坑。 笔试部分太久远,我就不怎么回忆了。直接将面试。 面试 如果说腾讯的面试是挥金如土...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

女朋友过生日,我花了20分钟给她写了一个代理服务器

女朋友说:“看你最近挺辛苦的,我送你一个礼物吧。你看看想要什么,我来准备。” 我想了半天,从书到鞋子到电子产品最后到生活用品,感觉自己什么都不缺,然后和她说:“你省省钱吧,我什么都不需要。” 她坚持要送:“不行,你一定要说一个礼物,我想送你东西了。” 于是,我认真了起来,拿起手机,上淘宝逛了几分钟,但还是没能想出来缺点什么,最后实在没办法了:“这样吧,如果你实在想送东西,那你就写一个代理服务器吧”...

记一次腾讯面试,我挂在了最熟悉不过的队列上……

腾讯后台面试,面试官问:如何自己实现队列?

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

HTTP与HTTPS的区别

面试官问HTTP与HTTPS的区别,我这样回答让他竖起大拇指!

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

立即提问
相关内容推荐