SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question OpenSSL Private Key Encryption

    Below is the code that I am using to encrypt some content using the OpenSSL private key.

    When content size is greater than 117 characters, I am getting false as a result of openssl_private_encrypt().

    PHP Code:
    <?php

    $strContent 
    "tSjvXuXQL3oK3zvkol9VwYHxvaiMPTCssKsBf0hXs0TT0Qxy2UHXckEGDVOYVhzQTzZVFfPKbrUo8fLQpCZWNQTzZVFfPKbrUo8fLQpCZWNQTzZVFfPKbrUo8fLQpCZWNQTzZVFfPKbrUo8fLQpCZWN8fLasd";

    $strPrivateKey = <<<CERT
    -----BEGIN RSA PRIVATE KEY-----
    MIICXAIBAAKBgQDX9uIKWzqz3+LBLHbpNCmRMKE/3QIn8rDISXsHSDh/Z8yEGcxp
    3oCK9ipqnzAnPpaXSRRyPFxroOrL1eG19hvd0JJNRyHtMhK5YauRfPKaZNYe4jgp
    17zyU4aGFsanJKXNyHJZM89gz9z6Q1nBCBVgMRJFMXktx2zKiVLO1MN68wIDAQAB
    AoGARgI9YngSfo78VfzRC2Yid3OZQjel5EdTMYpIfKLX1c1TShuG3WcIqoOEWo4C
    MSaj8KT7INEacLV4h91szuzaOSPj/8xlk9Nf7tluOmQ/OM/P3rkjydLUB7QZjCPv
    ao/HJG7TuSwYi6XjSPib9bLmXa9szVLDoXUjI9g/uTU8FxkCQQD+Lwz8q3BIfOgC
    HmZMAPWwv1kjR916PYj5r+dz7dqNkB09uyQIGlRqJPQ1rAH3yab6nMW6/mOn05lR
    s75oAuqVAkEA2YHr/0FCyMnPeh7apNtEGVwveLSp7/EboKcOS/LI6aFMEflNJvaE
    wi2xS7Zez5AfqdfHpZt6baBWiwxHZZ11ZwJBAOIYig3KlVL1QA56afYbOHAilLBs
    QVZ1m/y1ekTFgw0+7rO1XgSTHxlXi56eRRXa2lu7zapak9x5vLxPDQRJ680CQFMN
    4lDA2cCUFy6Zk4G53GIWqmXcDrv5hEQvJi1oEsHrfoGqgYRsQ7tl+Tpg9AksDnsr
    Uyfwm6o6vHEyCh1KJ+cCQBbYZKigAXalf3JLlbyoMUbqFmmiBctkM4gGfWdcNlEI
    6VI2TLjMyhXTWcrIZfkGg6P+wbidiLJKd10CUczAvks=
    -----END RSA PRIVATE KEY-----
    CERT;

    $bResult openssl_private_encrypt$strContent$strEncryptedContent$strPrivateKey );

    if( 
    $bResult == false )
    {
        echo 
    'Failed to encrypt the content' PHP_EOL PHP_EOL;
    }

    //If we don't use base64_encode here, we will get special chars in the o/p.
    echo 'Encrypted Content: ' base64_encode$strEncryptedContent ) . PHP_EOL PHP_EOL;
    Actually I am trying to encrypt the base64_encoded content using the private key.

    Is there anyway that I can know/get the reason for encryption failure?
    Last edited by ArunB; Apr 16, 2009 at 01:44. Reason: Changed the content size from 157 to 117.

  2. #2
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •