Labels

php (35) javascript (31) phpjavascript (30) jquery (23) html (20) mysql (14) database (9) codeigniter (4) json (4) bar chart (2) calendar (2) column chart (2) framework (2) google maps (2) query (2) tables (2) url (2) dropdown (1)

Tuesday, February 6, 2018

Encrypt a string with own encryption key using PHP

Data encryption is the more essential in the current world to maintain data privacy and to secure its form. Here we are providing a simple encryption method. Before explaining about coding will talk about Data Encryption.

Data encryption translates data into another form, or code so that only people with access to a secret key (formally called a decryption key) or password can read it. Encrypted data is commonly referred to as ciphertext, while unencrypted data is called plaintext. Currently, encryption is one of the most popular and effective data security methods used by organizations. Two main types of data encryption exist - asymmetric encryption, also known as public-key encryption, and symmetric encryption.
<?php
//sting which you want to encrypt
$str = 'http://www.phpjavascript.com/';
//the secryt key which encrypts the sting
$ky = 'ZCVGEGLLLS';

if ($ky == '') {
    echo $str;
} else {
    $ky = str_replace(chr(32), '', $ky);
    if (strlen($ky) < 8) {
        echo 'the key length should be more than 8';
    } else {
        $kl = strlen($ky) < 32 ? strlen($ky) : 32;
        $k = array();
        for ($i = 0; $i < $kl; $i++) {
            $k[$i] = ord($ky{$i}) & 0x1F;
        }
        $j = 0;
        for ($i = 0; $i < strlen($str); $i++) {
            $e = ord($str{$i});
            $str{$i} = $e & 0xE0 ? chr($e ^ $k[$j]) : chr($e);
            $j++;
            $j = $j == $kl ? 0 : $j;
        }
        echo $str;
    }
}
?>
Result:
rwbw?(#{{d4s~wofzmphjfs+dca#

21 comments:

  1. ethereumpro.net is best website to exchange ethereum to paypal.visit us for instant convert ethereum to paypal and other
    https://www.ethereumpro.net/

    ReplyDelete
  2. I have always admired your site, Thanks for the great tips and work .
    Ecommerce solutions Oman

    ReplyDelete
  3. I’m loving your posts and blogs. Some really helpful tips hints and information. Your posts are fun and informative, keep it up.

    Freelance mobile app designer


    ReplyDelete
  4. It is great to have the opportunity to read a good quality article with useful information.
    https://www.bharattaxi.com

    ReplyDelete
  5. I’m loving your posts and blogs. Some really helpful tips hints and information. Your posts are fun and informative, keep it up.
    SEO Services Pakistan

    ReplyDelete
  6. nice blog and most amazing matter you have some of great informative article on your blog to know or learn something. your content writing also most make your article readable and easy to understand. i think this most important part of success for blogger. on my work im always focus to learn something new and its another blog i got.Thanks to share and waiting for next! Adobe Photoshop Lightroom Classic CC 2018 v7.5 Free Download

    ReplyDelete
  7. Interesting blog.It would be great if you can provide more details about it. Thanks you

    ea games helpline number

    ea support phone number

    ReplyDelete
  8. https://www.zacoota.com/


    The UK's most visited estate agents.Our Experts can help you buy, sell, rent and let property with branches across the UK.

    online letting agent uk,property valuations uk,tenant agents uk,estate agents in uk,cheap property rental,property letting services,

    ReplyDelete
  9. I read Your Post Its Very Help Full and Its My Website
    Model Escorts in Lahore

    ReplyDelete
  10. This was really helpful for me, being a PHP developer, i really loved your post
    Get my blog post here TrakingPro

    ReplyDelete
  11. A changeset is a group of edits made by one user in a relatively bar cabinet short time. When you upload a changeset, the editor you are using will give you a chance of

    ReplyDelete
  12. Thanks for sharing such an awesome post. This is very informative and helpful, share more post like. Digital Signature Certificate

    ReplyDelete
  13. Thanks For Sharing This, Very Interesting And Helpful Support Provide By this blog. Digital Signature Certificate

    ReplyDelete
  14. I highly admire your post. Thanks for sharing such wonderful information, I see your post very often and share them on all social media channels.
    Private detective agency in Mumbai

    ReplyDelete
  15. It is an excellent post.sharing this sort of educational posts. Class 2 Digital Signature Certificate

    ReplyDelete
  16. It is an excellent post.sharing this sort of educational posts. Class 2 Digital Signature Certificate

    ReplyDelete
  17. I really enjoyed reading your blog, you have lots of great content. Please visit here:
    Digital Signature Certificate in Delhi

    ReplyDelete

More Posts

FOLLOW