How to Encrypt or Decrypt a String in PHPIn the PHP programming language, Encryption, as well as Decryption of string data, is accomplished using the OpenSSL function. Here, we can encrypt and decrypt value through openssl_encrypt(data) and openssl_decrypt(data) respectively. We can use a single method or both methods of PHP language. 1. openssl_encrypt(data) MethodThe encrypt function uses to encode the input value with many functionalities. We can get output values in difficult and safe coded formats. Syntax: The following syntax is used for the encrypt string data using php language. Parameters:Now, we can discuss syntax parameters for better understanding.
Return Value:
2. openssl_decrypt(data) methodThe decrypt function uses to decode the input value with much functionality. We can get the output value in the original format from the coded format. Syntax The following syntax uses for the decrypt string data using php language. parameters:Now, we can discuss syntax parameters for better understanding.
Return Value:
Examples The following examples show we encrypt and decrypt a string data using a php language. Example1 The following example shows encrypting a string of data using a php language. We require the input string, cipher method, and encryption key value to encrypt a string value. Output The following output shows encrypting a string of data using a php language. Example2 The following example shows the basic decrypting of string data using a php language. We require the input string, cipher method, and encryption key value to encrypt a string value. The encrypted value works as an input for decrypting data. Output The following output shows encrypting a string of data using a php language. Original String: Welcome to JavaTpoint learners Encrypted Input String: 47Qv+Tl92fM9MQyevgN3tyMA92KyNamCfx1ptqJ6R8Y= Decrypted Input String: Welcome to JavaTpoint learners Example3 The following example shows the basic decrypting of string data using a php language. We can use the multiple string functions in encrypt and decrypt functions. Output The following output shows encrypting a string of data using a php language. Example4 The following example shows the basic decrypting of string data using a php language. We can use the multiple dynamic string functions in encrypt and decrypt functions. Output The following output shows encrypting a string of data using a php language. ConclusionThe encrypt and decrypt string is an essential and safe function for the development process. It keeps and retrieves data safely without licking important values. The php functions create and display data without licking and destroying the original value.
Next Topic#
|