将JAVA SHA-512与Salesforce的Crypto Generated Digest相匹配

时间:2017-05-16 05:27:54

标签: java cryptography salesforce public-key-encryption sha512

我有一个密钥,正好在我的Java端使用SHA-512进行哈希处理,我在Salesforce中获得了相同密钥的SHA-512,但它不匹配,

这是关键

  

T100375 | Z123456 | 3.00 | 999999999 | https://c.ap2.visual.force.com/apex/ThankYou|45454545|test_1.00_0.00~test_1.00_0.00~test_1.00_0.00|prasad.vandavasi@techprocess.co.in|7506384658|11740|Prasad   万达瓦西| 7895455555 | Y | F | 40000000.00 | 6274148983DTKQQK

这是salesforce逻辑..

String salt = '6274148983DTKQQK' //String.valueOf(Crypto.getRandomInteger());
String key = 'T100375|Z123456|3.00|999999999|https://c.ap2.visual.force.com/apex/ThankYou|45454545|test_1.00_0.00~test_1.00_0.00~test_1.00_0.00|prasad.vandavasi@techprocess.co.in|7506384658|11740|Prasad Vandavasi|7895455555|Y|F|40000000.00|6274148983DTKQQK'

Blob digest = Crypto.generateDigest('SHA-512', Blob.valueOf(key));

生成以下

  

01b80979c6ea2fb6cca5864386ccc9109f6d05d1d9d1a553b2ac8f82ed347a00ed2d940e5e898c0611ebd4f20e41ed8d9619cec8d6e5e1e5a81e1b5d7e6c7dd3

这是我的java代码..

public static void main(String[] args)throws Exception
    {
        String password = "T100375|Z123456|3.00|999999999|https://c.ap2.visual.force.com/apex/ThankYou|45454545|test_1.00_0.00~test_1.00_0.00~test_1.00_0.00|prasad.vandavasi@techprocess.co.in|7506384658|11740|Prasad Vandavasi|7895455555|Y|F|40000000.00|6274148983DTKQQK";

        MessageDigest md = MessageDigest.getInstance("SHA-512");
        md.update(password.getBytes());

        byte byteData[] = md.digest();

        //convert the byte to hex format method 1
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < byteData.length; i++) {
         sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
        }

        System.out.println("Hex format : " + sb.toString());

        //convert the byte to hex format method 2
        StringBuffer hexString = new StringBuffer();
        for (int i=0;i<byteData.length;i++) {
            String hex=Integer.toHexString(0xff & byteData[i]);
            if(hex.length()==1) hexString.append('0');
            hexString.append(hex);
        }
        System.out.println("Hex format : " + hexString.toString());
    }

生成以下内容..

  

d5da285c8eb9e93f55185c36e00efccaf77ea778e3443e43b0f22e14600951c8bd61b847604b010e2ebc9b3fbea06c5b817ac8e560d8ae6e59d8e9cef89842d7

问题这两个都不匹配,关键,他们应该理想吗?我该怎么办才能让他们匹配?我可以编写Java逻辑来匹配,salesforce方面是我在java代码中必须遵守的东西,并且在salesforce方面无法做任何事情。

0 个答案:

没有答案