Md5Test.smali

.class public Lcom/cmcm/support/base/Md5Test;
.super Ljava/lang/Object;
.source "Md5Test.java"


# static fields
.field protected static hexDigits:[C

.field protected static messagedigest:Ljava/security/MessageDigest;


# direct methods
.method static constructor <clinit>()V
    .registers 1

    .prologue
    .line 15
    const/16 v0, 0x10

    new-array v0, v0, [C

    fill-array-data v0, :array_18

    sput-object v0, Lcom/cmcm/support/base/Md5Test;->hexDigits:[C

    .line 31
    const/4 v0, 0x0

    sput-object v0, Lcom/cmcm/support/base/Md5Test;->messagedigest:Ljava/security/MessageDigest;

    .line 34
    :try_start_c
    const-string v0, "MD5"

    invoke-static {v0}, Ljava/security/MessageDigest;->getInstance(Ljava/lang/String;)Ljava/security/MessageDigest;

    move-result-object v0

    sput-object v0, Lcom/cmcm/support/base/Md5Test;->messagedigest:Ljava/security/MessageDigest;
    :try_end_14
    .catch Ljava/security/NoSuchAlgorithmException; {:try_start_c .. :try_end_14} :catch_15

    .line 36
    :goto_14
    return-void

    .line 35
    :catch_15
    move-exception v0

    goto :goto_14

    .line 15
    nop

    :array_18
    .array-data 2
        0x30s
        0x31s
        0x32s
        0x33s
        0x34s
        0x35s
        0x36s
        0x37s
        0x38s
        0x39s
        0x61s
        0x62s
        0x63s
        0x64s
        0x65s
        0x66s
    .end array-data
.end method

.method public constructor <init>()V
    .registers 1

    .prologue
    .line 11
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method private static appendHexPair(BLjava/lang/StringBuffer;)V
    .registers 5

    .prologue
    .line 84
    sget-object v0, Lcom/cmcm/support/base/Md5Test;->hexDigits:[C

    and-int/lit16 v1, p0, 0xf0

    shr-int/lit8 v1, v1, 0x4

    aget-char v0, v0, v1

    .line 86
    sget-object v1, Lcom/cmcm/support/base/Md5Test;->hexDigits:[C

    and-int/lit8 v2, p0, 0xf

    aget-char v1, v1, v2

    .line 87
    invoke-virtual {p1, v0}, Ljava/lang/StringBuffer;->append(C)Ljava/lang/StringBuffer;

    .line 88
    invoke-virtual {p1, v1}, Ljava/lang/StringBuffer;->append(C)Ljava/lang/StringBuffer;

    .line 89
    return-void
.end method

.method public static bufferToHex([B)Ljava/lang/String;
    .registers 3

    .prologue
    .line 71
    const/4 v0, 0x0

    array-length v1, p0

    invoke-static {p0, v0, v1}, Lcom/cmcm/support/base/Md5Test;->bufferToHex([BII)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method private static bufferToHex([BII)Ljava/lang/String;
    .registers 6

    .prologue
    .line 75
    new-instance v0, Ljava/lang/StringBuffer;

    mul-int/lit8 v1, p2, 0x2

    invoke-direct {v0, v1}, Ljava/lang/StringBuffer;-><init>(I)V

    .line 76
    add-int v1, p1, p2

    .line 77
    :goto_9
    if-ge p1, v1, :cond_13

    .line 78
    aget-byte v2, p0, p1

    invoke-static {v2, v0}, Lcom/cmcm/support/base/Md5Test;->appendHexPair(BLjava/lang/StringBuffer;)V

    .line 77
    add-int/lit8 p1, p1, 0x1

    goto :goto_9

    .line 80
    :cond_13
    invoke-virtual {v0}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method public static getFileMD5String(Ljava/io/File;)Ljava/lang/String;
    .registers 6

    .prologue
    .line 39
    if-nez p0, :cond_5

    .line 40
    const-string v0, ""

    .line 61
    :goto_4
    return-object v0

    .line 42
    :cond_5
    const/4 v1, 0x0

    .line 44
    :try_start_6
    new-instance v0, Ljava/io/FileInputStream;

    invoke-direct {v0, p0}, Ljava/io/FileInputStream;-><init>(Ljava/io/File;)V
    :try_end_b
    .catch Ljava/io/FileNotFoundException; {:try_start_6 .. :try_end_b} :catch_10

    .line 47
    :goto_b
    if-nez v0, :cond_13

    .line 48
    const-string v0, ""

    goto :goto_4

    .line 45
    :catch_10
    move-exception v0

    move-object v0, v1

    goto :goto_b

    .line 50
    :cond_13
    const/16 v1, 0x400

    new-array v1, v1, [B

    .line 53
    :goto_17
    :try_start_17
    invoke-virtual {v0, v1}, Ljava/io/InputStream;->read([B)I

    move-result v2

    if-lez v2, :cond_25

    .line 54
    sget-object v3, Lcom/cmcm/support/base/Md5Test;->messagedigest:Ljava/security/MessageDigest;

    const/4 v4, 0x0

    invoke-virtual {v3, v1, v4, v2}, Ljava/security/MessageDigest;->update([BII)V
    :try_end_23
    .catch Ljava/io/IOException; {:try_start_17 .. :try_end_23} :catch_24

    goto :goto_17

    .line 56
    :catch_24
    move-exception v1

    .line 59
    :cond_25
    :try_start_25
    invoke-virtual {v0}, Ljava/io/InputStream;->close()V
    :try_end_28
    .catch Ljava/io/IOException; {:try_start_25 .. :try_end_28} :catch_33

    .line 61
    :goto_28
    sget-object v0, Lcom/cmcm/support/base/Md5Test;->messagedigest:Ljava/security/MessageDigest;

    invoke-virtual {v0}, Ljava/security/MessageDigest;->digest()[B

    move-result-object v0

    invoke-static {v0}, Lcom/cmcm/support/base/Md5Test;->bufferToHex([B)Ljava/lang/String;

    move-result-object v0

    goto :goto_4

    .line 60
    :catch_33
    move-exception v0

    goto :goto_28
.end method

.method public static getStringMD5(Ljava/lang/String;)Ljava/lang/String;
    .registers 3

    .prologue
    .line 65
    invoke-virtual {p0}, Ljava/lang/String;->getBytes()[B

    move-result-object v0

    .line 66
    sget-object v1, Lcom/cmcm/support/base/Md5Test;->messagedigest:Ljava/security/MessageDigest;

    invoke-virtual {v1, v0}, Ljava/security/MessageDigest;->update([B)V

    .line 67
    sget-object v0, Lcom/cmcm/support/base/Md5Test;->messagedigest:Ljava/security/MessageDigest;

    invoke-virtual {v0}, Ljava/security/MessageDigest;->digest()[B

    move-result-object v0

    invoke-static {v0}, Lcom/cmcm/support/base/Md5Test;->bufferToHex([B)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method