Wednesday, November 16, 2011

[java]如何將字串用SHA-1雜湊演算法加密?

為了要將從手機的IMEI加密接著傳入軟體,寫了以下方法,而以下的方法可以加密任何字串(只要你有需求的話),不過這裡是從取得手機的deviceID開始寫起。

//首先在activity的onCreat()方法中取得deviceID
TelephonyManager info = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);

String tempDeviceID = info.getDeviceId();

//接著將取得的deviceID用SHA-1雜湊演算法重新編碼
MessageDigest md = MessageDigest.getInstance("SHA1");
md.reset();
byte[] buffer = tempDeviceID.getBytes();
md.update(buffer);
byte[] digest = md.digest();

String deviceID = "";
for (int i = 0; i < digest.length; i++) {
    deviceID += Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1);
}

取得的deviceID即為重新加密編碼過的字串。

Monday, November 14, 2011

[OC]What is Objective-C?

Source Book:Xcode 4 iOS Development Beginner's Guide

Objective-C is an object-oriented programming language used by Apple primarily for programming Mac OS X, iPhone, and other iOS applications. It is an extension of the C Programming Language.

[iOS]Layers of the iOS architecture

Source Book:Xcode 4 iOS Development Beginner's Guide

1.The Core OS layer

This is the bottom layer of the hierarchy and is responsible for the foundation of the operating system which the other layers sit on top of. This important layer is in charge of managing memory—allocating and releasing memory once the application has finished with it, taking care of file system tasks, handling networking, and other operating system tasks. It also interacts directly with the hardware.The Core OS layer consists of the following components:


Monday, November 7, 2011

我也跳進了蘋果坑......

最近為了開發上的需要,也跳進了蘋果坑,入手了生平第一個蘋果產品:Macbook小白。

還在跟電腦培養感情,馬上就開始看程式奮鬥了,對於Xcode的操作非常不熟悉,還要在摸索好一陣子了。

my first mac

Xcode