设为首页 加入收藏

TOP

Object-C与Java通用的AES加密解密
2015-02-02 14:32:44 来源: 作者: 【 】 浏览:10
Tags:Object-C Java 通用 AES 加密解密

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加密解密


------------------------------------------分割线------------------------------------------


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android之增长的数字动画 下一篇Lua基础字符串操作

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: