OC and Java-generic AES encryption decryption

Source: Internet
Author: User
Tags decrypt

Recent projects using AES encryption, but in the Internet to find a lot of libraries are OC and Java encryption can not decrypt items, because our server is written in Java, so can not be used for iOS is a big trouble, Android is more leisurely to write in Java, so nothing. However, in the degree Niang body searched all over, or let me find this library, source remember not clear, before looking for a lot of many libraries. The following records the use of the method.

Example: Http://pan.baidu.com/s/1dDktRPn

OC Invocation Method:

  viewcontroller.m//  aestest////  Created by du Jia Li on 14-9-22.//  Copyright (c) 2014 du Jia Li. All rights reserved.//#import "ViewController.h" #include "nsdata+aes256.h" @interface Viewcontroller () @ End@implementation viewcontroller-(void) viewdidload{    [Super viewdidload];//do no additional setup after loading The view, typically from a nib.        nsstring* message = @ "Magic AES";        nsstring* str = [NSData aes256encryptwithplaintext:message];    nsstring* res = [NSData aes256decryptwithciphertext:str];    NSLog (@ "%@", str);    NSLog (@ "%@", res);} -(void) didreceivememorywarning{    [Super didreceivememorywarning];    Dispose of any resources the can be recreated.} @end


Java Call Method:

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 {@Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); AES MAes = new AES (); String mstring = "magical AES"; byte[] mBytes = null;try {mBytes = mstring.getbytes ("UTF8");} catch (Exception e) {//Todo:hand Le exception}string enstring = Maes.encrypt (mBytes); LOG.I ("aes123", enstring); String destring = Maes.decrypt (enstring); LOG.I ("aes123", destring);} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}

Original address: http://blog.csdn.net/qqmcy/article/details/39483075

OC and Java-generic AES encryption decryption

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.