All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sequoiadb.util.SdbDesEcbDecryptor Maven / Gradle / Ivy

There is a newer version: 5.10
Show newest version
package com.sequoiadb.util;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import com.sequoiadb.exception.BaseException;
import com.sequoiadb.exception.SDBError;

class SdbDesEcbDecryptor {
    private Cipher cipher;

    SdbDesEcbDecryptor(byte[] key) {
        try {
            int mode = Cipher.DECRYPT_MODE;
            SecretKeySpec keySpec = new SecretKeySpec(key, "DES");
            cipher = Cipher.getInstance("DES/ECB/NoPadding");
            cipher.init(mode, keySpec);
        }
        catch (Exception e) {
            throw new BaseException(SDBError.SDB_INVALIDARG, "init cipher failed", e);
        }
    }

    public byte[] desDecrypt(byte[] encryptedValue) {
        try {
            return cipher.doFinal(encryptedValue);
        }
        catch (Exception e) {
            throw new BaseException(SDBError.SDB_INVALIDARG, "descrypt failed", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy