openssl_sign(): supplied key param cannot be coerced into a private key

September 19, 2015 § Leave a comment

Hello, just wanted to write something coming back after a long time. Please excuse my absence, life has been very busy with so much other priorities.

This post is for those who are using a PHP-DKIM solution and experiencing this below error –

openssl_sign(): supplied key param cannot be coerced into a private key

This happens when you have inputted a wrong private key input in the openssl_sign(). The third parameter is actually the “private key id” received from a call on openssl_get_privatekey(). But often its mistakenly gets passed with a string value of the private key lines.

So, here is the solution –
1) Prepare the “private key id”:
$fp = fopen("/path/to/file/.htkeyprivate", "r");
$privKey = fread($fp, 8192);
fclose($fp);
$pKeyId = openssl_get_privatekey($privKey, 'optional_passphrase');

2) Use in the openssl_sign:
openssl_sign($dataToSign, $signatureVar, $pKeyId);

If you’re using PHP-DKIM class based solution (object oriented), you may put the below code in the _construct() of the main class:

public function __construct()
{
$fp = fopen("/path/to/file/.htkeyprivate", "r");
$privKey = fread($fp, 8192);
fclose($fp);
$pKeyId = openssl_get_privatekey($privKey, 'optional_passphase');

$this->open_SSL_priv = $pKeyId;
}

Hope this helps you. I will definitely try to write again whenever I get time. Theres a lot to share from regular development experiences but time has bound me.

Happy Blogging!

Advertisements

Create Short URL using our URL Shrinker at RUPOM.NET

December 13, 2009 § 3 Comments

Today we have released a free URL Shrinking service at http://rupom.net which creates shortest possible URL from your long URL input. As the usage of internet is increasing on and people being connected to each other using social networks and social medias as well as the usual options like email, personal website, blog, etc., the necessity of a good and short URL has been very important.

For example: I have been a proud father recently and created a blog post in my blog which is available at https://rupom.wordpress.com/2009/10/07/i-have-been-a-proud-father-found-meaning-of-life/. Now I want to share this link with friends & family members but it is too big to remember or memorize for anyone. So I went to http://rupom.net/ and created a short URL http://rupom.net/fatherhood (I used “fatherhood” in the keyword field) which is very easier to remember/memorize. You click on this link and find the correct destination URL https://rupom.wordpress.com/2009/10/07/i-have-been-a-proud-father-found-meaning-of-life/. There are more places this short URL can be used especially in http://twitter.com where you can’t write more than 140 characters in your post.

RUPOM.NET creates shortest possible URL for you that never expires. If you want to use this service from within your website, you can easily do so using our API help or our HTML form code.

To protect spammers, we have set a time gap of 15 seconds between two consecutive requests from an IP address. But still if you need more facilities, please feel free to contact with us. Also, facilities to track your stats can be provided upon request.

Please start using our URL Shrinking service today and send us comments/feedbacks.

Thanks.

Some helpful Firefox add-ons for web developers

December 11, 2009 § 4 Comments

I want to share some helpful Firefox add-ons that you might like. In my case, they all help me a lot in my development.

Helpful Firefox add-ons:

Firebug: Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.

See more info: https://addons.mozilla.org/en-US/firefox/addon/1843

Firepicker: Simple color picker plugin for Firebug.

See more info: https://addons.mozilla.org/en-US/firefox/addon/15032

Live HTTP Headers: View HTTP headers of a page and while browsing.

See more info: https://addons.mozilla.org/en-US/firefox/addon/3829

Quick Java: Allows quick enable and disable of Java and Javascript from the status bar.

See more info: https://addons.mozilla.org/en-US/firefox/addon/1237

SEO Live YSRank: Live search rank at the status bar, top searched keywords and search volume data for a specific site. Great for search marketing, keywords research and SEO.

See more info: https://addons.mozilla.org/en-US/firefox/addon/15067

IE Tab: This is a great tool for web developers, since you can easily see how your web page displayed in IE with just one click and then switch back to Firefox.

See more info: https://addons.mozilla.org/en-US/firefox/addon/1419

Validator: This addon for Firebug will send the current HTML source to http://validator.w3.org/check and display any errors that are returned by this service.

See more info: https://addons.mozilla.org/en-US/firefox/addon/14860

View Source Chart: This add-on:
* Graphically Displays HTML Tag Boundaries
* Graphically Defines Tag Nesting Order, Structure and Hierarchy
* Adds Simple and Powerful UI *to* Source Code

See more info: https://addons.mozilla.org/en-US/firefox/addon/655

CSS Reloader: CSS Reloader is an extension that allows you to reload all the CSS of any site without you have to reload the page itself. You can use the keyboard shortcut F9, or the context-menu’s option “Reload CSS” to reload the CSS files or at page.

Very useful especially when you do pixel pushing.

See more info: https://addons.mozilla.org/en-US/firefox/addon/46211

FireFTP: FireFTP is a free, secure, cross-platform FTP client for Mozilla Firefox which provides easy and intuitive access to FTP servers.

See more info: https://addons.mozilla.org/en-US/firefox/addon/684

InfoRSS: Displays RSS, Atom, parsed HTML and NNTP feed in a scrolling area in the status bar. Compatible with podcasting RSS which can be downloaded directly. It’s also a good Google email notifier.

See more info: https://addons.mozilla.org/en-US/firefox/addon/361

Link Checker: Check the validity of links on any webpage.

See more info: https://addons.mozilla.org/en-US/firefox/addon/532

RSS Validator: Validates a page using the W3C RSS Validator.

See more info: https://addons.mozilla.org/en-US/firefox/addon/2294?src=reco

Hope this helps. I will share more in future.

Thanks.

Set your own timezone on a shared hosting

December 6, 2009 § 7 Comments

If you are a web application developer and had opportunities to work on various client servers around the globe, you may have already experienced the timezone related problems in the server script. This problem comes when the hosting is a shared one and the website runs for a different timezone than the server’s timezone. For example – I am running a website for my local community here in Dhaka/Bangladesh (timezone GMT + 7.00) but my server which is a shared one resides in the United States (say a timezone like GMT – 7). As this is a shared server, the timezone was set by the administrator to their local time. So every call to PHP date() and/or time() function will always return the server’s local time causing a mismatch with my local time in my website.

To overcome this situation, you have to change your default date time using PHP function date_default_timezone_set(your_time_zone_string). For my case, it was following:

date_default_timezone_set('Asia/Dhaka');

Add this line before executing/calling any date and/or time functions.

Below might be a quick test for you:

—————————
<?php
echo 'OLD Time: ' . date('Y-m-d H:i:s a');

date_default_timezone_set('Asia/Dhaka');

echo '<br />';

echo 'New Time: ' . date('Y-m-d H:i:s a');
?>
—————————-

That’s it.

Read more on function date_default_timezone_set: http://us3.php.net/date_default_timezone_set

See the list of supported timezones here: http://us3.php.net/manual/en/timezones.php

Happy PHPing!

Google Base Data API Error – You must specify an id for this item

March 31, 2009 § Leave a comment

For those who have recently faced this error during product uploading to Google Base, please note that you have to add an additional attribute <g:id> with each of your entries. Google has recently added more documentation on this:

http://code.google.com/apis/base/starting-out.html#products

Thanks.


Rupom

Class Text Search Replace : New Update

February 23, 2008 § 8 Comments

Today I made an update of my class “Text Search Replace” at PHPClasses.org. This update will increase the search capability of the class. The initial release of the class could not search some special characters (well, I just forgot & missed this to put with the initial release). Later a user of this class (his name is “Robert”) noticed the problem and asked me for a solution. I was too busy to touch the class. But I managed time and fixed it. You can now work with special characters(especially the ones are part of regular expression syntax). I am sure this fix has increased the usability of this class to a large extent.

Please download the latest version from here:
http://www.phpclasses.org/browse/package/3211.html

Special thanks to Robert who noticed and informed me about the problem.

If you are a user of this class, please send me bugs, etc so I can work to improve its performances.


Rupom

Hello AOL Address Book Grabber Seekers

October 21, 2007 § 5 Comments

For AOL address book grabber seekers:

I am getting a lot of requests of “AOL Address Book Grabber” PHP code. For your information – please don’t send me emails. Instead, please fill the following form:

http://www.rupom.com/aol/post-your-email.php

I am a very busy guy and don’t have time to reply to all emails separately. So I thought I would collect interested emails using this form and then reply to the emails on each Saturday. I understand your need and importance of time, but I am sorry I can’t manage time except Saturday.

You may ask why I am not putting a download option of the code. I would like to reply I am sorry I have problems.

Best regards.

Rupom

Where Am I?

You are currently browsing the PHP Helps category at Rupom Here.