##### Coverage Report - jp.co.y_net.amm.common.CalcHash

Classes in this File | Line Coverage | Branch Coverage | Complexity

CalcHash

0% | 0/34

0% | 0/6

0.0;0

1

     package jp.co.y_net.amm.common;

2

3

     import java.security.MessageDigest;

4

     import java.security.NoSuchAlgorithmException;

5

6

0

     public class CalcHash {

7

0

     //    private static int STRETCH_COUNT = 500;

8

         public static String passowrdHash(String password, String account) {

9

0

     //        String salt = getSha256(loginId);

10

0

     //        String hash = "";

11

     //

12

0

     //        for (int i = 0; i < STRETCH_COUNT; i++) {

13

0

     //            hash = getSha256(hash + salt + password);

14

     //        }

15

     //        return hash;

16

0

17

0

             return getSha256(account+":"+password);

18

         }

19

0

         public static String challengeResponse(String phash, String chvalue) {

20

             //return getSha256(passwordHash + challenge);

21

0

             return getSha256(phash+":"+chvalue);

22

         }

23

         /*

24

          * 文字列から SHA256 のハッシュ値を取得

25

0

          */

26

0

         private static String getSha256(String target) {

27

0

             MessageDigest md = null;

28

0

             StringBuilder buf = new StringBuilder();

29

0

             try {

30

0

                 md = MessageDigest.getInstance("SHA-256");

31

0

                 md.update(target.getBytes());

32

0

                 byte[] digest = md.digest();

33

0

34

0

                 for (int i = 0; i < digest.length; i++) {

35

0

                     buf.append(String.format("%02x", digest[i]));

36

0

                 }

37

0

38

0

             } catch (NoSuchAlgorithmException e) {

39

0

                 throw new RuntimeException(e);

40

0

             }

41

42

0

             return buf.toString();

43

         }

44

45

         /*---------------------------------------------------------------------------------------------------------------*/

46

         /* 単体テスト*/

47

0

48

0

         public static void main(String[] args) {

49

0

             System.out.println(passowrdHash("p@ssw0rd", "ryoma.sakamoto@example.com"));

50

0

             System.out.println(passowrdHash("test", "kondou@example.com"));

51

0

             System.out.println(passowrdHash("testtest", "okita@example.com"));

52

0

             System.out.println(passowrdHash("testtest", "admin"));

53

0

         }

54

55

     }