packageorg.owasp.mastestapp;importandroid.content.Context;importandroid.util.Base64;importjava.security.Key;importjava.security.SecureRandom;importjavax.crypto.Cipher;importjavax.crypto.SecretKey;importjavax.crypto.SecretKeyFactory;importjavax.crypto.spec.DESKeySpec;importjavax.crypto.spec.DESedeKeySpec;importjavax.crypto.spec.SecretKeySpec;importkotlin.Metadata;importkotlin.jvm.internal.Intrinsics;importkotlin.text.Charsets;/* compiled from: MastgTest.kt */@Metadata(d1={"\u0000\u001a\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0006\b\u0007\u0018\u00002\u00020\u0001B\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u0006\u0010\u0005\u001a\u00020\u0006J\u000e\u0010\u0007\u001a\u00020\u00062\u0006\u0010\b\u001a\u00020\u0006J\u000e\u0010\t\u001a\u00020\u00062\u0006\u0010\b\u001a\u00020\u0006J\u000e\u0010\n\u001a\u00020\u00062\u0006\u0010\b\u001a\u00020\u0006J\u000e\u0010\u000b\u001a\u00020\u00062\u0006\u0010\b\u001a\u00020\u0006R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\f"},d2={"Lorg/owasp/mastestapp/MastgTest;","","context","Landroid/content/Context;","(Landroid/content/Context;)V","mastgTest","","vulnerable3DesEncryption","data","vulnerableBlowfishEncryption","vulnerableDesEncryption","vulnerableRc4Encryption","app_debug"},k=1,mv={1,9,0},xi=48)/* loaded from: classes4.dex */publicfinalclassMastgTest{publicstaticfinalint$stable=8;privatefinalContextcontext;publicMastgTest(Contextcontext){Intrinsics.checkNotNullParameter(context,"context");this.context=context;}publicfinalStringvulnerableDesEncryption(Stringdata){Intrinsics.checkNotNullParameter(data,"data");try{byte[]keyBytes=newbyte[8];newSecureRandom().nextBytes(keyBytes);DESKeySpeckeySpec=newDESKeySpec(keyBytes);SecretKeyFactorykeyFactory=SecretKeyFactory.getInstance("DES");KeygenerateSecret=keyFactory.generateSecret(keySpec);Intrinsics.checkNotNullExpressionValue(generateSecret,"generateSecret(...)");KeysecretKey=generateSecret;Ciphercipher=Cipher.getInstance("DES");cipher.init(1,secretKey);byte[]bytes=data.getBytes(Charsets.UTF_8);Intrinsics.checkNotNullExpressionValue(bytes,"this as java.lang.String).getBytes(charset)");byte[]encryptedData=cipher.doFinal(bytes);StringencodeToString=Base64.encodeToString(encryptedData,0);Intrinsics.checkNotNullExpressionValue(encodeToString,"encodeToString(...)");returnencodeToString;}catch(Exceptione){return"Encryption error: "+e.getMessage();}}publicfinalStringvulnerable3DesEncryption(Stringdata){Intrinsics.checkNotNullParameter(data,"data");try{byte[]keyBytes=newbyte[24];newSecureRandom().nextBytes(keyBytes);DESedeKeySpeckeySpec=newDESedeKeySpec(keyBytes);SecretKeyFactorykeyFactory=SecretKeyFactory.getInstance("DESede");KeygenerateSecret=keyFactory.generateSecret(keySpec);Intrinsics.checkNotNullExpressionValue(generateSecret,"generateSecret(...)");KeysecretKey=generateSecret;Ciphercipher=Cipher.getInstance("DESede");cipher.init(1,secretKey);byte[]bytes=data.getBytes(Charsets.UTF_8);Intrinsics.checkNotNullExpressionValue(bytes,"this as java.lang.String).getBytes(charset)");byte[]encryptedData=cipher.doFinal(bytes);StringencodeToString=Base64.encodeToString(encryptedData,0);Intrinsics.checkNotNullExpressionValue(encodeToString,"encodeToString(...)");returnencodeToString;}catch(Exceptione){return"Encryption error: "+e.getMessage();}}publicfinalStringvulnerableRc4Encryption(Stringdata){Intrinsics.checkNotNullParameter(data,"data");try{byte[]keyBytes=newbyte[16];newSecureRandom().nextBytes(keyBytes);SecretKeySpecsecretKey=newSecretKeySpec(keyBytes,"RC4");Ciphercipher=Cipher.getInstance("RC4");cipher.init(1,secretKey);byte[]bytes=data.getBytes(Charsets.UTF_8);Intrinsics.checkNotNullExpressionValue(bytes,"this as java.lang.String).getBytes(charset)");byte[]encryptedData=cipher.doFinal(bytes);StringencodeToString=Base64.encodeToString(encryptedData,0);Intrinsics.checkNotNull(encodeToString);returnencodeToString;}catch(Exceptione){return"Encryption error: "+e.getMessage();}}publicfinalStringvulnerableBlowfishEncryption(Stringdata){Intrinsics.checkNotNullParameter(data,"data");try{byte[]keyBytes=newbyte[8];newSecureRandom().nextBytes(keyBytes);SecretKeysecretKey=newSecretKeySpec(keyBytes,"Blowfish");Ciphercipher=Cipher.getInstance("Blowfish");cipher.init(1,secretKey);byte[]bytes=data.getBytes(Charsets.UTF_8);Intrinsics.checkNotNullExpressionValue(bytes,"this as java.lang.String).getBytes(charset)");byte[]encryptedData=cipher.doFinal(bytes);StringencodeToString=Base64.encodeToString(encryptedData,0);Intrinsics.checkNotNull(encodeToString);returnencodeToString;}catch(Exceptione){return"Encryption error: "+e.getMessage();}}publicfinalStringmastgTest(){StringdesEncryptedString=vulnerableDesEncryption("Hello from the OWASP MASTG Test app.");StringtripleDesEncryptedString=vulnerable3DesEncryption("Hello from the OWASP MASTG Test app.");Stringrc4EncryptedString=vulnerableRc4Encryption("Hello from the OWASP MASTG Test app.");StringblowfishEncryptedString=vulnerableBlowfishEncryption("Hello from the OWASP MASTG Test app.");return"DES Encrypted: "+desEncryptedString+"\n3DES Encrypted: "+tripleDesEncryptedString+"\nRC4 Encrypted: "+rc4EncryptedString+"\nBlowfish Encrypted: "+blowfishEncryptedString;}}
rules:-id:weak-encryption-algorithmslanguages:-javaseverity:WARNINGmetadata:summary:Thisrulelooksforweakencryptionalgorithms.message:"[MASVS-CRYPTO-1] Weak encryption algorithms found in use."pattern-regex:Cipher\.getInstance\("?(DES|DESede|RC4|Blowfish)(/[A-Za-z0-9]+(/[A-Za-z0-9]+)?)?"?\)
The rule has identified two instances in the code file where insecure encryption algorithms are used. The specified line numbers can be located in the reverse-engineered code for further investigation and remediation.