Checksum Verification
How to verify Collect SDK checksum
tasks.register("verifyCollectChecksum") {
doLast {
val dependencies = configurations.getByName("implementationDependenciesMetadata") // Get all dependencies with added as implementation
val dependency = dependencies.find { it.name.contains("vgscollect") } // Get collect dependency
println(dependency)
val expectedChecksum = "<HASH_VALUE>" // Replace with the expected SHA-256 checksum
if (dependency != null) {
val sha256 = calculateSHA256(dependency) // Calculate collect dependency SHA-256 checksum
println("Downloaded artifact checksum: $sha256")
if (sha256 == expectedChecksum) {
println("Checksum matches. The artifact is valid.")
} else {
throw Exception("Checksum mismatch! The artifact may be corrupted or tampered with.")
}
} else {
throw Exception("Artifact not found!")
}
}
}
// Function to calculate the SHA-256 checksum of a dependency file
fun calculateSHA256(file: File): String {
val digest = MessageDigest.getInstance("SHA-256")
file.inputStream().use { inputStream ->
val buffer = ByteArray(8192)
var bytesRead: Int
while (inputStream.read(buffer).also { bytesRead = it } != -1) {
digest.update(buffer, 0, bytesRead)
}
}
return digest.digest().joinToString("") { "%02x".format(it) }
}Last updated

