I'm trying to rewrite the code below in php:
Code: Select all
#import <openssl/rsa.h>
#import <openssl/bio.h>
#import <openssl/pem.h>
unsigned char *privateKey = "....";
const char *clearText = "string test";
/* get private RSA */
BIO *privateBIO = BIO_new_mem_buf(privateKey, strlen(privateKey));
RSA *privateRSA = NULL;
PEM_read_bio_RSAPrivateKey(privateBIO, &privateRSA, NULL, NULL);
/* generate hash string */
unsigned char md[SHA_DIGEST_LENGTH];
SHA1((unsigned char *)clearText, strlen(clearText), md);
for(int i=0; i<sizeof(md); i++) printf("%x", md[i]);
/* encrypt data */
unsigned int outlen;
unsigned char outbuf[RSA_size(privateRSA)];
RSA_sign(NID_sha1, md, sizeof(md), outbuf, &outlen, privateRSA);
BIO_free(privateBIO);
RSA_free(privateRSA);
for(int i=0; i<outlen; i++) printf("%c", outbuf[i]);Code: Select all
<?php
$private_key = "...";
$stringToEncrypt = "string test";
//create hash of string
$hash = sha1(utf8_encode($stringToEncrypt));
echo $hash;
?>I'm sorry but I've few knowledgments of php!!!
Thanks in advance for any help!