package org.bouncycastle.openpgp;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bouncycastle.util.encoders.Hex;

/* JADX INFO: loaded from: classes3.dex */
public class PGPSessionKey {
    private final int algorithm;
    private final byte[] sessionKey;

    public PGPSessionKey(int i, byte[] bArr) {
        this.algorithm = i;
        this.sessionKey = bArr;
    }

    public static PGPSessionKey fromAsciiRepresentation(String str) {
        Matcher matcher = Pattern.compile("(\\d{1,3}):([0-9A-Fa-f]+)").matcher(str);
        if (!matcher.matches()) {
            throw new IllegalArgumentException("Provided ascii encoding does not match expected format <algo-num>:<hex-key>");
        }
        return new PGPSessionKey(Integer.parseInt(matcher.group(1)), Hex.decode(matcher.group(2)));
    }

    public int getAlgorithm() {
        return this.algorithm;
    }

    public byte[] getKey() {
        byte[] bArr = new byte[this.sessionKey.length];
        System.arraycopy(this.sessionKey, 0, bArr, 0, this.sessionKey.length);
        return bArr;
    }

    public String toString() {
        return this.algorithm + ":" + this.sessionKey;
    }
}
