@Deen
You are using SHA-1 encrypting in the code you posted. Which is what my example you used does... not SHA-256. The correct value for SHA-256 encryption is
6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090
for an input value of:
abc123
Your requirements go far beyond just a regular SHA-256 hash and several components of those instructions make little to no sense to me. They appear to be written for some specific platform rather than a generalization...
Step 4. The notion of removing a binary '0x' doesn't make sense, but lets assume that this just means that we want to convert the byte array produced in step2 to a string of hex values in the form of
6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090
rather than
0x6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090
No matter what, this isn't 'binary'
Next, we want to convert that value to lower case, so step4 is ultimately equal to
abc1236ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090
or are we expected to somewhere convert the result of step 1 to a hex string as well?
616263313233366ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090
Is this then meant to get hashed with SHA-256 as a string or as a byte array of itself? Very unclear instructions...
Finally in Step 8, I've never heard of anything called ME998 before, so, I am left to assume this is some internal system or table to your environment.
Regardless of the method I tried as outlined above, I cannot produce the 'expected' output you provided.
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import javax.xml.bind.DatatypeConverter
def toHexString(byte[] bytes) {
return DatatypeConverter.printHexBinary(bytes)
}
def toByteArray(String s) {
return DatatypeConverter.parseHexBinary(s)
}
def Sha256(byte[] bytes) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-256")
md.update(bytes)
return md.digest()
}
def Base64(byte[] bytes) {
return new String(Base64.getEncoder().encodeToString(bytes))
}
def merryGoRound(byte[] bytes) {
step6 = bytes
for (i=0; i<1000; i++) { step6 = Sha256(step6) }
return step6
}
def DeenEncrypt1(String input) {
step2 = Sha256(input.getBytes())
step3 = input + toHexString(step2)
step4 = step3.toLowerCase()
step5 = Sha256(step4.getBytes())
step6 = merryGoRound(step5)
step7 = Base64(step6)
return step7
}
def DeenEncrypt2(String input) {
step2 = Sha256(input.getBytes())
step3 = toHexString(input.getBytes()) + toHexString(step2)
step4 = step3.toLowerCase()
step5 = Sha256(step4.getBytes())
step6 = merryGoRound(step5)
step7 = Base64(step6)
return step7
}
def DeenEncrypt3(String input) {
step2 = Sha256(input.getBytes())
step3 = toHexString(input.getBytes()) + toHexString(step2)
step4 = step3.toLowerCase()
step5 = Sha256(toByteArray(step4))
step6 = merryGoRound(step5)
step7 = Base64(step6)
return step7
}
def to0xString(byte[] bytes) { return "0x" + toHexString(bytes) } def DeenEncrypt4(String input) { step2 = Sha256(input.getBytes()) step3 = input + toHexString(step2) step4 = step3.toLowerCase() step5 = Sha256(step4.getBytes()) step6 = to0xString(step5) for (i=0; i<999; i++) { step6 = to0xString(Sha256(step6.getBytes()))} step7 = Base64(Sha256(step6.getBytes())) return step7 }
myString="abc123" println(DeenEncrypt1(myString)) //Ir4+t3lTvPeE0s+daBIZY3btG0u8ist8znq6FnhIJNc= println(DeenEncrypt2(myString)) //UqPhYbaI/bZ5s7jO3jnVIfPP4mT+BvPDYLWgInRSHB4= println(DeenEncrypt3(myString)) //pobTckp4TAuDudylcugnzJGBc9YM4poSUPRk2zTgHrY= println(DeenEncrypt4(myString)) //2wQPtEPxQJLCkmpH1Bo4t1OFqdcnGR8bzA7/uUrDiTY=
I would recommend you get some clearer hashing requirements
... View more