Object-C调用方法:
//
//? ViewController.m
//? AESTest
//
//? Created by 杜甲 on 14-9-22.
//? Copyright (c) 2014年 杜甲. All rights reserved.
//
#import "ViewController.h"
#include "NSData+AES256.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
? ? [super viewDidLoad];
?// Do any additional setup after loading the view, typically from a nib.
? ?
? ? NSString* message = @"神奇的AES";
? ?
? ? NSString* str = [NSData AES256EncryptWithPlainText:message];
? ? NSString* res = [NSData AES256DecryptWithCiphertext:str];
? ? NSLog(@"%@",str);
? ? NSLog(@"%@",res);
}
- (void)didReceiveMemoryWarning
{
? ? [super didReceiveMemoryWarning];
? ? // Dispose of any resources that can be recreated.
}
@end
Java调用方法:
package com.test.aesforandroid;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
?@Override
?protected void onCreate(Bundle savedInstanceState) {
? super.onCreate(savedInstanceState);
? setContentView(R.layout.activity_main);
? AES mAes = new AES();
?
? String mString = "神奇的AES";
? byte[] mBytes = null;
?
?
? try {
? ?mBytes = mString.getBytes("UTF8");
? ?
? ?
? ?
? } catch (Exception e) {
? ?// TODO: handle exception
? }
? String enString = mAes.encrypt(mBytes);
? Log.i("aes123", enString);
? String deString = mAes.decrypt(enString);
? Log.i("aes123", deString);
?}
?@Override
?public boolean onCreateOptionsMenu(Menu menu) {
? // Inflate the menu; this adds items to the action bar if it is present.
? getMenuInflater().inflate(R.menu.main, menu);
? return true;
?}
}
------------------------------------------End------------------------------------------
最后附上本文代码工程源码链接:
具体下载目录在 /2014年资料/12月/15日/Object-C与Java通用的AES加密解密
------------------------------------------分割线------------------------------------------