/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model.person;

//import java.nio.charset.Charset;
import java.security.SecureRandom;
import java.util.Arrays;
import javax.persistence.Entity;

import model.AbstractEntity;

/**
 *
 * @author Patrick
 */
@Entity
public class Salt extends AbstractEntity {

    //private final Charset UTF8_CHARSET = Charset.forName("UTF-8");
    private static final long serialVersionUID = -1068077226987746862L;
    private byte[] salt;
    private int interations;

    public Salt() {
        interations = 3072;
        generateSalt();
    }

    private void generateSalt() {
        SecureRandom random = new SecureRandom();
        byte bytes[] = new byte[64];
        random.nextBytes(bytes);
        salt = bytes;
    }

    public java.lang.String bytetoString(byte[] input) {
        return Arrays.toString(input);
    }

    public byte[] getSalt() {
        return salt;
    }

    public int getInterations() {
        return interations;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + Arrays.hashCode(this.salt);
        hash = 79 * hash + this.interations;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Salt other = (Salt) obj;
        if (this.interations != other.interations) {
            return false;
        }
        if (!Arrays.equals(this.salt, other.salt)) {
            return false;
        }
        return true;
    }
}
