顯示具有 JAVA 標籤的文章。 顯示所有文章
顯示具有 JAVA 標籤的文章。 顯示所有文章

2015年6月29日 星期一

[Android]如何從 APK 拿到 SHA1 key

解開 apk 檔案取得
META-INF\CERT.SF

keytool -printcert -file CERT.RSA
就可得到如下結果

擁有者: EMAILADDRESS=oneplus@oneplus.cn, CN=OnePlus, OU=SW, O=OnePlus, L=Shenzhen, ST=Guangdong, C=CN
發出者: EMAILADDRESS=oneplus@oneplus.cn, CN=OnePlus, OU=SW, O=OnePlus, L=Shenzhen, ST=Guangdong, C=CN
序號: 8abe4e1ae1d847f1
有效期自: Thu May 07 15:25:19 CST 2015 到: Mon Sep 22 15:25:19 CST 2042
憑證指紋:
         MD5:  62:08:F4:ED:35:9F:F6:60:43:A0:31:A7:A7:9B:F6:06
         SHA1: B7:91:45:D7:9F:8F:14:C2:6C:68:EC:BB:27:8D:56:AE:43:65:B1:61
         SHA256: 46:81:AD:50:CA:FC:58:0E:DF:E0:27:BD:3F:E5:93:25:4E:72:CD:2D:EF:1B:35:1F:EA:30:6C:CF:62:20:CF:07
         簽章演算法名稱: SHA1withRSA
         版本: 3

擴充套件:

#1: ObjectId: 2.5.29.35 Criticality=false
AuthorityKeyIdentifier [
KeyIdentifier [
0000: 54 61 E2 B1 A9 15 E1 4D   9F 0F 92 DD 48 01 13 31  Ta.....M....H..1
0010: A8 49 AE 64                                        .I.d
]
]

#2: ObjectId: 2.5.29.19 Criticality=false
BasicConstraints:[
  CA:true
  PathLen:2147483647
]

#3: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 54 61 E2 B1 A9 15 E1 4D   9F 0F 92 DD 48 01 13 31  Ta.....M....H..1
0010: A8 49 AE 64                                        .I.d
]
]














2015年6月14日 星期日

[Android]產生keystore

release:


$ keytool -genkey -v -keystore my-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000


debug:


$ keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000


get release finger print:


$ keytool -list -v -keystore [keystore path] -alias [alias-name] -storepass [storepass] -keypass [keypass]



get debug finger print:

$ keytool -list -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android

2015年4月13日 星期一

[JAVA] java memory mode with "volatile" & "synchronized"

As a matter of fact, the Java memory model is such that a modification
to a variable in one thread may not immediately be visible to other threads. Actually, it
may never be visible. Consider the code in Listing 5–11: if one thread calls
MyClass.loop(), and at some point in the future another thread calls
Myclass.setValue(100), the first thread may still not terminate; may carry on looping
forever and always print out a value other than 100, simply because of the Java
language’s memory model.
Listing 5–11. Java Memory Model Impact
public class MyClass {
     private static final String TAG = "MyClass";
     private static int mValue = 0;
     public static void setValue(int n) {
          mValue = n;
     }
     public static void loop () {
          while (mValue != 100) {
               try {
                    Log.i(TAG, “Value is ” + mValue);
                    Thread.sleep(1000);
               } catch (Exception e) {
                    // ignored
               }
          }
     }
}
You have two options to fix that:
Use the synchronized keyword, as shown in Listing 5–12.
Use the volatile keyword, as shown in Listing 5–13.
Listing 5–12. Adding the Synchronized Keyword
public class MyClass {
     private static final String TAG = "MyClass";
     private static int mValue = 0;
     public static synchronized void setValue(int n) {
          mValue = n;
     }
     public static synchronized int getValue() {
          return mValue;
     }
     public static void loop () {
          int value;
          while ((value = getValue()) != 100) {
          try {
               Log.i(TAG, “Value is ” + value);
               Thread.sleep(1000);
               } catch (Exception e) {
              // ignored
               }
          }
     }
}

Listing 5–13. Adding the Volatile Keyword
public class MyClass {
     private static final String TAG = "MyClass";
     private static volatile int mValue = 0; // we add the volatile keyword and remove
     the synchronize keyword
     public static void setValue(int n) {
          mValue = n; // you’d still have to use synchronized if that statement were mValue += n (not atomic)
     }
     public static void loop () {
          while (mValue != 100) {
               try {
               Log.i(TAG, “Value is ” + mValue);
               Thread.sleep(1000);
               } catch (Exception e) {
              // ignored
               }
          }
     }
}

2015年4月7日 星期二

[Android][Java] Java define 4 reference type

Strong
Soft
Weak
Phantom

it is important to avoid memory leak
Android’s LruCache uses strong references