Skip to content

Instantly share code, notes, and snippets.

@100n0m3
Created November 22, 2017 12:08
Show Gist options
  • Save 100n0m3/50bfcd2bd1864c23435eda252759506e to your computer and use it in GitHub Desktop.
Save 100n0m3/50bfcd2bd1864c23435eda252759506e to your computer and use it in GitHub Desktop.
.class public Lbr/gov/fazenda/receita/rfb/util/Hash;
.super Ljava/lang/Object;
.source "Hash.java"
# static fields
.field private static final ALGORITIMO_HASH:Ljava/lang/String;
# direct methods
.method static constructor <clinit>()V
.locals 2
.prologue
.line 23
new-instance v0, Lbr/gov/fazenda/receita/rfb/util/ObfuscatedString;
const/4 v1, 0x2
new-array v1, v1, [J
fill-array-data v1, :array_0
invoke-direct {v0, v1}, Lbr/gov/fazenda/receita/rfb/util/ObfuscatedString;-><init>([J)V
.line 24
invoke-virtual {v0}, Lbr/gov/fazenda/receita/rfb/util/ObfuscatedString;->toString()Ljava/lang/String;
move-result-object v0
sput-object v0, Lbr/gov/fazenda/receita/rfb/util/Hash;->ALGORITIMO_HASH:Ljava/lang/String;
.line 23
return-void
:array_0
.array-data 8
-0x33c7a6a3d153e9f3L # -1.528415446109808E59
0x6617344f7585217cL # 6.162352608672665E183
.end array-data
.end method
.method public constructor <init>()V
.locals 0
.prologue
.line 19
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
.method public static decrypt([B[BLjava/lang/String;)[B
.locals 4
.param p0, "raw" # [B
.param p1, "encrypted" # [B
.param p2, "algoritmo" # Ljava/lang/String;
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
.prologue
.line 85
new-instance v2, Ljavax/crypto/spec/SecretKeySpec;
invoke-direct {v2, p0, p2}, Ljavax/crypto/spec/SecretKeySpec;-><init>([BLjava/lang/String;)V
.line 86
.local v2, "skeySpec":Ljavax/crypto/spec/SecretKeySpec;
invoke-static {p2}, Ljavax/crypto/Cipher;->getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;
move-result-object v0
.line 87
.local v0, "cipher":Ljavax/crypto/Cipher;
const/4 v3, 0x2
invoke-virtual {v0, v3, v2}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;)V
.line 88
invoke-virtual {v0, p1}, Ljavax/crypto/Cipher;->doFinal([B)[B
move-result-object v1
.line 89
.local v1, "decrypted":[B
return-object v1
.end method
.method public static encrypt([B[BLjava/lang/String;)[B
.locals 4
.param p0, "raw" # [B
.param p1, "clear" # [B
.param p2, "algoritmo" # Ljava/lang/String;
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/lang/Exception;
}
.end annotation
.prologue
.line 76
new-instance v2, Ljavax/crypto/spec/SecretKeySpec;
invoke-direct {v2, p0, p2}, Ljavax/crypto/spec/SecretKeySpec;-><init>([BLjava/lang/String;)V
.line 77
.local v2, "skeySpec":Ljavax/crypto/spec/SecretKeySpec;
invoke-static {p2}, Ljavax/crypto/Cipher;->getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;
move-result-object v0
.line 78
.local v0, "cipher":Ljavax/crypto/Cipher;
const/4 v3, 0x1
invoke-virtual {v0, v3, v2}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;)V
.line 79
invoke-virtual {v0, p1}, Ljavax/crypto/Cipher;->doFinal([B)[B
move-result-object v1
.line 80
.local v1, "encrypted":[B
return-object v1
.end method
.method public static generateHash(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
.locals 7
.param p0, "key" # Ljava/lang/String;
.param p1, "text" # Ljava/lang/String;
.prologue
.line 37
new-instance v2, Ljavax/crypto/spec/SecretKeySpec;
invoke-virtual {p0}, Ljava/lang/String;->getBytes()[B
move-result-object v5
sget-object v6, Lbr/gov/fazenda/receita/rfb/util/Hash;->ALGORITIMO_HASH:Ljava/lang/String;
invoke-direct {v2, v5, v6}, Ljavax/crypto/spec/SecretKeySpec;-><init>([BLjava/lang/String;)V
.line 41
.local v2, "keySpec":Ljavax/crypto/spec/SecretKeySpec;
:try_start_0
sget-object v5, Lbr/gov/fazenda/receita/rfb/util/Hash;->ALGORITIMO_HASH:Ljava/lang/String;
invoke-static {v5}, Ljavax/crypto/Mac;->getInstance(Ljava/lang/String;)Ljavax/crypto/Mac;
move-result-object v3
.line 42
.local v3, "mac":Ljavax/crypto/Mac;
invoke-virtual {v3, v2}, Ljavax/crypto/Mac;->init(Ljava/security/Key;)V
.line 43
const-string v5, "UTF-8"
invoke-virtual {p1, v5}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B
move-result-object v5
invoke-virtual {v3, v5}, Ljavax/crypto/Mac;->doFinal([B)[B
move-result-object v4
.line 44
.local v4, "rawMac":[B
new-instance v5, Lorg/apache/commons/codec/binary/Hex;
invoke-direct {v5}, Lorg/apache/commons/codec/binary/Hex;-><init>()V
invoke-virtual {v5, v4}, Lorg/apache/commons/codec/binary/Hex;->encode([B)[B
move-result-object v1
.line 45
.local v1, "hexBytes":[B
new-instance v5, Ljava/lang/String;
const-string v6, "ISO-8859-1"
invoke-direct {v5, v1, v6}, Ljava/lang/String;-><init>([BLjava/lang/String;)V
:try_end_0
.catch Ljava/security/NoSuchAlgorithmException; {:try_start_0 .. :try_end_0} :catch_0
.catch Ljava/security/InvalidKeyException; {:try_start_0 .. :try_end_0} :catch_1
.catch Ljava/io/UnsupportedEncodingException; {:try_start_0 .. :try_end_0} :catch_2
.line 54
.end local v1 # "hexBytes":[B
.end local v3 # "mac":Ljavax/crypto/Mac;
.end local v4 # "rawMac":[B
:goto_0
return-object v5
.line 46
:catch_0
move-exception v0
.line 47
.local v0, "e":Ljava/security/NoSuchAlgorithmException;
invoke-virtual {v0}, Ljava/security/NoSuchAlgorithmException;->printStackTrace()V
.line 54
.end local v0 # "e":Ljava/security/NoSuchAlgorithmException;
:goto_1
const/4 v5, 0x0
goto :goto_0
.line 48
:catch_1
move-exception v0
.line 49
.local v0, "e":Ljava/security/InvalidKeyException;
invoke-virtual {v0}, Ljava/security/InvalidKeyException;->printStackTrace()V
goto :goto_1
.line 50
.end local v0 # "e":Ljava/security/InvalidKeyException;
:catch_2
move-exception v0
.line 51
.local v0, "e":Ljava/io/UnsupportedEncodingException;
invoke-virtual {v0}, Ljava/io/UnsupportedEncodingException;->printStackTrace()V
goto :goto_1
.end method
.method public static keyGen(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)[B
.locals 5
.param p0, "key" # Ljava/lang/String;
.param p1, "algoritmo" # Ljava/lang/String;
.param p2, "secure" # Ljava/lang/String;
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/security/NoSuchAlgorithmException;
}
.end annotation
.prologue
.line 65
invoke-virtual {p0}, Ljava/lang/String;->getBytes()[B
move-result-object v0
.line 66
.local v0, "keyStart":[B
invoke-static {p1}, Ljavax/crypto/KeyGenerator;->getInstance(Ljava/lang/String;)Ljavax/crypto/KeyGenerator;
move-result-object v1
.line 67
.local v1, "kgen":Ljavax/crypto/KeyGenerator;
invoke-static {p2}, Ljava/security/SecureRandom;->getInstance(Ljava/lang/String;)Ljava/security/SecureRandom;
move-result-object v3
.line 68
.local v3, "sr":Ljava/security/SecureRandom;
invoke-virtual {v3, v0}, Ljava/security/SecureRandom;->setSeed([B)V
.line 69
const/16 v4, 0x80
invoke-virtual {v1, v4, v3}, Ljavax/crypto/KeyGenerator;->init(ILjava/security/SecureRandom;)V
.line 70
invoke-virtual {v1}, Ljavax/crypto/KeyGenerator;->generateKey()Ljavax/crypto/SecretKey;
move-result-object v2
.line 71
.local v2, "skey":Ljavax/crypto/SecretKey;
invoke-interface {v2}, Ljavax/crypto/SecretKey;->getEncoded()[B
move-result-object v4
return-object v4
.end method
.method public static validateHash(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z
.locals 2
.param p0, "key" # Ljava/lang/String;
.param p1, "text" # Ljava/lang/String;
.param p2, "expectedHash" # Ljava/lang/String;
.prologue
.line 59
invoke-static {p0, p1}, Lbr/gov/fazenda/receita/rfb/util/Hash;->generateHash(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
move-result-object v0
.line 60
.local v0, "hash":Ljava/lang/String;
invoke-virtual {p2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
move-result v1
return v1
.end method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment