Hi Tom,
Thanks for being with us and all your support.
Suppose I have a File Name :- "MPR_YES_CDC_11122018_V1.csv"
Checksum of the given file as per below java code :- cab5f886bba15048a6f7180665871a2fa4ad4917
In the same manner I have to use below java code into my PLSQL code to get checksum of the given file name, I have tried using
select standard_hash ('MPR_YES_CDC_11122018_V1_.csv', 'SHA1' )
from dual but the output of checksum is not matching with the output of the java checksum.
Is there anyway by which we can use below java code into my PLSQL code.
private String generateChecksum() {
//Create checksum for this file
File file = new File("D:\\MPR_FILES\\MPR_YES_CDC_11122018_V1_cab5f886bba15048a6f7180665871a2fa4ad4917.csv");
//Get the checksum
String checksum = getFileChecksum(file);
//see checksum
System.out.println(checksum);
return checksum;
}
private String getFileChecksum(File file)
{
StringBuilder sb = new StringBuilder();
try {
//Use SHA-1 algorithm
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
//Get file input stream for reading the file content
FileInputStream fis = new FileInputStream(file);
//Create byte array to read data in chunks
byte[] byteArray = new byte[1024];
int bytesCount = 0;
//Read file data and update in message digest
while ((bytesCount = fis.read(byteArray)) != -1) {
messageDigest.update(byteArray, 0, bytesCount);
};
//close the stream; We don't need it now.
fis.close();
//Get the hash's bytes
byte[] bytes = messageDigest.digest();
//This bytes[] has bytes in decimal format;
//Convert it to hexadecimal format
for(int i=0; i< bytes.length ;i++)
{
sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
}
} catch (Exception e) {
System.out.println("Exception : "+ e.getMessage());
}
//return complete hash
return sb.toString();
}