package com.jscape.inet.ssh.util.keyreader;

import com.jscape.util.io.DataTools;
import com.jscape.util.io.MemorySource;
import com.jscape.util.keystore.PemPkcs8KeyPairCodec;
import com.jscape.util.keystore.Pkcs8KeyPairCodec;

import java.security.KeyPair;

/**
 * @author Alex Usun
 */
public class Pkcs8KeyPairFormat
        implements KeyPairFormat {

    @Override
    public KeyPair restoreKeyPair(byte[] data, String passphrase)
            throws FormatException {
        try {
            return DataTools.read(new MemorySource(data), PemPkcs8KeyPairCodec.bcCodec(), Pkcs8KeyPairCodec.bcCodec());
        } catch (Exception e) {
            throw new FormatException(e);
        }
    }
}
