{"id":44,"date":"2013-03-19T17:44:25","date_gmt":"2013-03-19T17:44:25","guid":{"rendered":"http:\/\/ecodebook.wordpress.com\/?p=44"},"modified":"2013-03-19T17:44:25","modified_gmt":"2013-03-19T17:44:25","slug":"php-string-encryption-and-decryption","status":"publish","type":"post","link":"https:\/\/blog.mycarts.shop\/?p=44","title":{"rendered":"PHP: String encryption and decryption"},"content":{"rendered":"<h4>String Encryption<\/h4>\n<p>[code language=&#8221;php&#8221;]<br \/>\n$string = &quot;Some String to encrypted&quot;;<\/p>\n<p>$key = &quot;secretscode&quot;;<br \/>\n$cipher_alg = MCRYPT_RIJNDAEL_128;<br \/>\n$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND);<br \/>\n$encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_CBC, $iv);<\/p>\n<p>print &quot;Encrypted string: &quot;.bin2hex($encrypted_string).&quot;<br \/>\n&quot;;<br \/>\n[\/code]<\/p>\n<p>Encrypted string: b7634f7632625ce353d651a771a49c6b308f8c8e7bd2d96a224837f7c65b3ac2<\/p>\n<h4>String Decryption<\/h4>\n<p>[code language=&#8221;php&#8221;]<br \/>\n$decrypted_string = mcrypt_decrypt($cipher_alg, $key, $encrypted_string, MCRYPT_MODE_CBC, $iv);<\/p>\n<p>print &quot;Decrypted string: $decrypted_string&quot;;<br \/>\n[\/code]<\/p>\n<p>Decrypted string: Some String to encrypted<\/p>\n","protected":false},"excerpt":{"rendered":"<p>String Encryption [code language=&#8221;php&#8221;] $string = &quot;Some String to encrypted&quot;; $key = &quot;secretscode&quot;; $cipher_alg = MCRYPT_RIJNDAEL_128; $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND); $encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_CBC, $iv); print &quot;Encrypted string: &quot;.bin2hex($encrypted_string).&quot; &quot;; [\/code] Encrypted string: b7634f7632625ce353d651a771a49c6b308f8c8e7bd2d96a224837f7c65b3ac2 String Decryption [code language=&#8221;php&#8221;] $decrypted_string = mcrypt_decrypt($cipher_alg, $key, $encrypted_string, MCRYPT_MODE_CBC, $iv); print &quot;Decrypted string: $decrypted_string&quot;; [\/code] Decrypted string:&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=44"}],"version-history":[{"count":0,"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=\/wp\/v2\/posts\/44\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}