ARIA 추가

master
mjkhan21 12 months ago
parent 6b94287244
commit 5e331b873f

@ -0,0 +1,120 @@
package cokr.xit.foundation.data;
import java.util.Base64;
import org.egovframe.rte.fdl.cryptography.EgovPasswordEncoder;
import org.egovframe.rte.fdl.cryptography.impl.EgovARIACryptoServiceImpl;
import cokr.xit.foundation.AbstractComponent;
/**ARIA /
* @author mjkhan
*/
public class ARIA extends AbstractComponent {
private String
key,
algorithm;
private int blockSize;
private EgovPasswordEncoder passwordEncoder;
private EgovARIACryptoServiceImpl aria;
/** .
* @return
*/
public String getKey() {
return key;
}
/** .
* @param key
* @return ARIA
*/
public ARIA setKey(String key) {
this.key = key;
return this;
}
/** . SHA-256.
* @return
*/
public String getAlgorithm() {
return algorithm;
}
/** . SHA-256.
* @param algorithm
* @return ARIA
*/
public ARIA setAlgorithm(String algorithm) {
this.algorithm = algorithm;
return this;
}
/** . 1024.
* @return
*/
public int getBlockSize() {
return blockSize < 1 ? 1024 : blockSize;
}
/** . 1024.
* @param blockSize
* @return ARIA
*/
public ARIA setBlockSize(int blockSize) {
this.blockSize = blockSize;
return this;
}
/** () .
* @param plain ()
* @return
*/
public String encrypt(String plain) {
if (isEmpty(plain)) return "";
byte[] bytes = service().encrypt(plain.getBytes(), key);
return Base64.getEncoder().encodeToString(bytes);
}
private EgovPasswordEncoder passwordEncoder() {
if (passwordEncoder == null) {
passwordEncoder = new EgovPasswordEncoder();
String hashed = passwordEncoder.encryptPassword(notEmpty(key, "key"));
passwordEncoder.setHashedPassword(hashed);
if (!isEmpty(algorithm))
passwordEncoder.setAlgorithm(algorithm);
}
return passwordEncoder;
}
private EgovARIACryptoServiceImpl service() {
if (aria == null) {
aria = new EgovARIACryptoServiceImpl();
aria.setPasswordEncoder(passwordEncoder());
aria.setBlockSize(getBlockSize());
}
return aria;
}
/** () .
* @param encrypted ()
* @return
*/
public String decrypt(String encrypted) {
byte[] bytes = Base64.getDecoder().decode(encrypted);
return new String(service().decrypt(bytes, key));
}
/** .
* @return ARIA
*/
public ARIA clear() {
key = algorithm = null;
blockSize = 0;
passwordEncoder = null;
aria = null;
return this;
}
}
Loading…
Cancel
Save