Need matching PHP encryption function -
I created a multi-piece app 3 years ago which encrypts on the NAT side and decrypts on the PHP side. I have never created this encrypted function because I do not think I'll need it. Now I do, and I do not remember where I got the PHP decry. I do not know the php encryption well to make it from scratch and it works with my existing PHP decrypt () function.
I need someone to indicate in a PHP Encrypt () function that my PHP decrypt () decryption will correct all the details below.
.NET encrypt function:
Private string encrypt (string plain text) {if string string (. String) is returned. Empty; String passphrase = "secret1"; String nosed = "secret 2"; Int PasswordTestation = 1000; String initVector = "pOWaTbO92LfXbh69JkYzfT7P465TNc0h"; Int keySisson = 256; Byte [] initVectorBytes = encoding. ASCII.GetBytes (initVector); Byte [] SaltVolibits = Encoding. ASCII Gatebytes (saltvalue); Byte [] Plain Textbits = Encoding. UTF8.GetBytes (Plain Text); Rfc2898 Darevibets Password = New RFC 2898 Derivatives (Passphrases, Nakwolyutites, PasswordInternational); Byte [] keyBytes = password.GetBytes (keySize / 8); // Create the raw Rijndael encryption object; RegendLL managed sumometric = new resendell managed (); Symmetric.backsis = 256; SymmetricKey.KeySize = 256; Symmetric.padding = paddingmode Zoros; SymmetricKey.Mode = Ciphermode.cBC; ICryptoTransform encryptor = symmetricKey.CreateEncryptor (keyBytes, initVectorBytes); Memorystream memorystream = new memorystream (); Cryptostream Cryptostream = New cryptoStream (MemoryStream, Encryptor, Cryptostarm. Right); Cryptostream Type (plain text, 0, plain text.); CryptoStream.FlushFinalBlock (); Byte [] Ciphertestbows = Memorystream. ToArray (); MemoryStream.Close (); CryptoStream.Close (); String cipher text = convert ToBase64String (Ciphertextbits); Return ciphertext; }
PHP decrypt function:
function decrypt ($ encrypted text) {$ p = "secret1"; $ S = "secret2"; $ Iv = "Pava TBO 92 LFXH69 JK Wijfi 7 P 465 TNCH"; $ C = 1000; $ Kl = 32; $ A = 'sha1'; $ HL = Stellen (hash ($ A, blank, true)); #hash length $ kb = roof ($ kl / $ hl); $ Dk = # important block to calculate ''; # Generate key for removed key # ($ block = 1; $ block & lt; = $ kb; $ block ++) # # The initial hash for this block is $ ib = $ b = hash_hammak ($ a, $ s Pack ('n', $ block), $ p, truth); Execute block iterations for # $ (= I = 1; $ i & lt; $ c; $ i ++) # Each extract is $ ib ^ = ($ b = hash_hmac ($ a, $ b, $ p, True)); $ Dk $ $ Ib; # Block blocking} $ key = substr ($ dk, 0, $ kl); $ Plane = rtrim (mcrypt_decrypt (MCRYPT_RIJNDAEL_256, $ key, base64_decode ($ encryptedText), MCRYPT_MODE_CBC, $ iv)); $ TextArray = str_split ($ plain text); Foreign Currency ($ text $ Array as Array) {$ ascii = ord ($ char); If ($ ascii <32 || $ ascii> 127) {return ""; }} $ Plaintext returned; }
My .NET encrypt () and PHP decrypt () do great work together, no problem. The developer is a PHP encryption protagonist that can show me a php encrypt () function that works with a php decrypt () function
with an encryption example: "SnoqL / xcgfFBkhZld + QXRnsl7zS9viJpJsbm4MocDUQ =" For decrypts string "443" no quotes.
Below is an encrypted code with the evidence 'This is an exam!' The input of my decrypt function is encrypted with my function which decodes it successfully and prints 'This is a test!' on screen.
& lt;? Echo decrypt (encrypt ('this is an exam!')); Function Encrypt ($ plain text) {$ key = createKey (); $ EncryptedText = rtrim (base64_encode (mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $ key, $ plane, MCRYPT_MODE_CBC, "pOWaTbO92LfXbh69JkYzfT7P465TNc0h"))); Return $ $ encrypted text; } Function decrypt ($ encrypted text) {$ key = createKey (); $ Plane = rtrim (mcrypt_decrypt (MCRYPT_RIJNDAEL_256, $ key, base64_decode ($ encryptedText), MCRYPT_MODE_CBC, "pOWaTbO92LfXbh69JkYzfT7P465TNc0h")); Return $ plaintext; } Create the function () {$ p = "secret1"; $ S = "secret2"; $ Dk = ''; ($ Block = 1; $ block & lt; = 2; $ block ++) {$ ib = $ b = hash_hammak ('sha1', $ s pack ('n', $ block), $ p, true) ; For ($ i = 1; $ i <1000; $ i ++) $ ib ^ = ($ b = hash_hammack ('sha1', $ b, $ p, true)); $ Dk $ $ Ib; } Return substrate ($ dk, 0, 32); }
An ADKE () function has been created that enters several duplicate codes outside of our otherwise simplified decrypt () / encrypt () functions.
Comments
Post a Comment