APP Project user password transmission has never been useful HTTPS, In consideration of the privacy of the user, use AES Encrypt password , In the future, it can also be used for encrypted interaction between mobile phone and server .

PHP Free Edition phpAES project , There are all kinds of errors in decoding on the mobile phone .

It's hard to find PHP ANDROID IOS, Mutual encryption and decryption is normal AES Encryption algorithm code .

PHP Of AES encryption algorithm :

<?php
class MCrypt {
private $hex_iv = '00000000000000000000000000000000'; # converted JAVA byte code in to HEX and placed it here
private $key = 'p4ssw0rd'; #Same as in JAVA
function __construct() {
$this->key = hash('sha256', $this->key, true);
//echo $this->key.'<br/>';
}
function encrypt($str) {
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($td, $this->key, $this->hexToStr($this->hex_iv));
$block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$pad = $block - (strlen($str) % $block);
$str .= str_repeat(chr($pad), $pad);
$encrypted = mcrypt_generic($td, $str);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return base64_encode($encrypted);
}
function decrypt($code) {
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($td, $this->key, $this->hexToStr($this->hex_iv));
$str = mdecrypt_generic($td, base64_decode($code));
$block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $this->strippadding($str);
}
/*
For PKCS7 padding
*/
private function addpadding($string, $blocksize = 16) {
$len = strlen($string);
$pad = $blocksize - ($len % $blocksize);
$string .= str_repeat(chr($pad), $pad);
return $string;
}
private function strippadding($string) {
$slast = ord(substr($string, -1));
$slastc = chr($slast);
$pcheck = substr($string, -$slast);
if (preg_match("/$slastc{" . $slast . "}/", $string)) {
$string = substr($string, 0, strlen($string) - $slast);
return $string;
} else {
return false;
}
}
function hexToStr($hex)
{
$string='';
for ($i=0; $i < strlen($hex)-1; $i+=2)
{
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
}
$encryption = new MCrypt();
echo $encryption->encrypt('top secret message') . "<br/>";
echo $encryption->decrypt('EQyz+ukU+ss+Sinf15bApdYj5ANrRwY632v8EhrzLPk=');
?>

java Of AES encryption algorithm :

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import android.util.Base64;
/**
* @author vipin.cb , vipin.cb@experionglobal.com <br>
* Sep 27, 2013, 5:18:34 PM <br>
* Package:- <b>com.veebow.util</b> <br>
* Project:- <b>Veebow</b>
* <p>
*/
public class AESCrypt {
private final Cipher cipher;
private final SecretKeySpec key;
private AlgorithmParameterSpec spec;
public static final String SEED_16_CHARACTER = "U1MjU1M0FDOUZ.Qz";
public AESCrypt() throws Exception {
// hash password with SHA-256 and crop the output to 128-bit for key
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.update(SEED_16_CHARACTER.getBytes("UTF-8"));
byte[] keyBytes = new byte[32];
System.arraycopy(digest.digest(), 0, keyBytes, 0, keyBytes.length);
cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
key = new SecretKeySpec(keyBytes, "AES");
spec = getIV();
}
public AlgorithmParameterSpec getIV() {
byte[] iv = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
IvParameterSpec ivParameterSpec;
ivParameterSpec = new IvParameterSpec(iv);
return ivParameterSpec;
}
public String encrypt(String plainText) throws Exception {
cipher.init(Cipher.ENCRYPT_MODE, key, spec);
byte[] encrypted = cipher.doFinal(plainText.getBytes("UTF-8"));
String encryptedText = new String(Base64.encode(encrypted,
Base64.DEFAULT), "UTF-8");
return encryptedText;
}
public String decrypt(String cryptedText) throws Exception {
cipher.init(Cipher.DECRYPT_MODE, key, spec);
byte[] bytes = Base64.decode(cryptedText, Base64.DEFAULT);
byte[] decrypted = cipher.doFinal(bytes);
String decryptedText = new String(decrypted, "UTF-8");
return decryptedText;
}
}

IOS Of AES encryption algorithm :

https://github.com/Gurpartap/AESCrypt-ObjC

stackoverflow Reference resources
http://stackoverflow.com/questions/5928915/wanted-compatible-aes-code-encrypt-decrypt-for-iphone-android-windows-xp

http://stackoverflow.com/questions/19196728/aes-128-encryption-in-java-decryption-in-php

from :http://www.funboxpower.com/php_android_ios_aes

【 turn 】PHP android ios Compatible AES More related articles on encryption algorithm

  1. PHP android ios Compatible AES encryption algorithm

    APP Project user password transmission has never been useful HTTPS, In consideration of the privacy of the user, use AES Encrypt password , In the future, it can also be used for encrypted interaction between mobile phone and server . PHP Free Edition phpAES project , There are all kinds of errors in decoding on the mobile phone . It's hard to find PHP ...

  2. iOS,Android,WP, .NET Universal AES encryption algorithm

    These two days for mobile App Development API, As a result, the implementation of encryption verification encountered a big hole . Here we have to make complaints about the stinking and hard ones iOS,Windows Server Unable to decrypt the correct result ,Android Then you can , And then we used the generic AES256 Encryption calculation ...

  3. windows phone and android,ios Of touch Event compatible

    1. Development background Recently, with html5 I wrote a little game , There are countless pits in the middle , There are many even Baidu can't find the answer , so html5 It's really immature , Compatibility is more complex than ie6 go beyond , The slag is barely able to make complaints about it .. Okay , I make complaints about it , ...

  4. iOS,Android,.NET Universal AES encryption algorithm

    original text :iOS,Android,.NET Universal AES encryption algorithm These two days for mobile App Development API, As a result, the implementation of encryption verification encountered a big hole . Here we have to make complaints about the stinking and hard ones iOS,Windows Server Unable to decrypt the correct result ...

  5. Android IOS WebRTC Summary of audio and video development ( eighty-five )-- Use WebRTC Broadcast webcam video ( Next )

    This paper mainly introduces WebRTC ( We translated and organized , translator :weizhenwei, check :blacker), It was first published in [ Wind net ] Support the original , Reprint must indicate the source , Welcome to my WeChat official account. blacker( WeChat ID:bl ...

  6. Android IOS WebRTC Summary of audio and video development ( eighty-three )-- Use WebRTC Broadcast webcam video ( On )

    This paper mainly introduces WebRTC ( We translated and organized , translator :weizhenwei, check :blacker), It was first published in [ Wind net ] Support the original , Reprint must indicate the source , Welcome to my WeChat official account. blacker( WeChat ID:bl ...

  7. Tomcat two-way Https Verify build , Personal implementation with mainstream browsers 、Android/iOS Mobile client super secure communication

    Then <Tomcat A one-way Https Verify build , Personal implementation with mainstream browsers .Android/iOS Mobile client secure communication >, Here's a more secure two-way Https Authentication communication mechanism , For clarity , The following is a separate description ...

  8. Tomcat A one-way Https Verify build , Personal implementation with mainstream browsers 、Android/iOS Mobile client secure communication

    as everyone knows ,iOS9 It has started to be used by default in networking Https Replace the original Http Request the , although Http and Https Each has its own advantages , But on the whole , Now in this secure information age , Developers can't do without Https 了 . online ...

  9. Android IOS WebRTC Summary of audio and video development ( 6、 ... and )-- iOS Tearful experience of development

    I was engaged in webrtc iOS Development , So change the title to Android IOS WebRTC Summary of audio and video development , The following is a summary of the experience in the development process , Reprint please explain the source ( Blog Garden RTC.Blacker): 1. IO ...

Random recommendation

  1. POJ2492 A Bug&#39;s Life

    Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 33833   Accepted: 11078 Description Ba ...

  2. About Linux In the file , Some thoughts on links

    stay Unix In the system , The operating system is text and image on disk , Mouse and keyboard operation , Network interaction, etc IO Operations design a set of common API. So that when they are processed, they can be processed in the same way as byte stream . So , In addition to the process , Everything else can be seen as a document . Linu ...

  3. LeetCode 942 DI String Match Problem solving report

    Subject requirements Given a string S that only contains "I" (increase) or "D" (decrease), let N ...

  4. Python Solve the mess

    solve python The code problem The string is in python The internal use of unicode Coding method of , therefore , When doing code conversion , It is usually necessary to unicode As an intermediate code , That is, decoding other encoded strings first (decode) become unicode ...

  5. hdu 1278 Escape the maze

    Escape the maze Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. NSNotificationCenter Be careful

    Pairs appear It's very simple ,NSNotificationCenter The receiving thread of the message is based on the thread sending the message . That's synchronous , therefore , occasionally , The message you sent may not be in the main thread , And we all know how to do it UI Must be on the main thread , Otherwise it will appear ...

  7. The front-end study -- Inline framework iframe

    Inline framework iframe You can introduce other external pages into a page Content in inline frames is not retrieved by search engines , So try not to use inline framework in development <iframe></iframe> attribute : sr ...

  8. Oracle The database lists all the table names SQL sentence

    select table_name from user_tables

  9. IE6 Next css common bug Handle

    1. Double margin As shown in the figure below , A style is set with “float:left:” And then there is “margin-left:100px:” The situation of , It's a double . If the outer margin is set to 100px, On the left, it shows 200px, solve ...

  10. CSDN Site system upgrade announcement

    Ladies and gentlemen CSDN user : How do you do . CSDN The site will be 2015 year 12 month 17 Japan 23 when -12 month 18 Japan 08 Upgrade and maintain the system , Upgrade maintenance period ,CSDN The site will be affected . It could lead to blogs . Download channel and other functions of the site can't ...