// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
// 
// 	private static final String KEY_ALGORITHM = "MASTERKEY";
// 	public static final String ENC_ALG = "AES";
// 	public static final String MAC_ALG = "HmacSHA256";
// 	public static final int SUBKEY_LEN_BYTES = 32;
// 
// 	public Masterkey(byte[] key) {
// 		super(checkKeyLength(key), KEY_ALGORITHM);
// 	}
// 
// 	private static byte[] checkKeyLength(byte[] key) {
// 		Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// 		return key;
// 	}
// 
// 	public static Masterkey generate(SecureRandom csprng) {
// 		byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// 		try {
// 			csprng.nextBytes(key);
// 			return new Masterkey(key);
// 		} finally {
// 			Arrays.fill(key, (byte) 0x00);
// 		}
// 	}
// 
// 	public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// 		Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// 		Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// 		byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// 		try {
// 			System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// 			System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// 			return new Masterkey(key);
// 		} finally {
// 			Arrays.fill(key, (byte) 0x00);
// 		}
// 	}
// 
// 	@Override
// 	public Masterkey copy() {
// 		return new Masterkey(getEncoded());
// 	}
// 
// 	/**
// 	 * Get the encryption subkey.
// 	 *
// 	 * @return A new copy of the subkey used for encryption
// 	 */
// 	public DestroyableSecretKey getEncKey() {
// 		return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// 	}
// 
// 	/**
// 	 * Get the MAC subkey.
// 	 *
// 	 * @return A new copy of the subkey used for message authentication
// 	 */
// 	public DestroyableSecretKey getMacKey() {
// 		return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// 	}
// 
// }
// 
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
// 
// 	public MasterkeyLoadingFailedException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public MasterkeyLoadingFailedException(String message) {
// 		super(message);
// 	}
// 
// }


import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.ECPrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Arrays;
package org.cryptomator.cryptolib.common;



public class MasterkeyHubAccessTest {

	private ECPrivateKey devicePrivateKey;

	@BeforeEach
	public void setup() throws NoSuchAlgorithmException, InvalidKeySpecException {
		byte[] keyBytes = BaseEncoding.base64Url().decode("ME4CAQAwEAYHKoZIzj0CAQYFK4EEACIENzA1AgEBBDDzj9mBnoqoYTO0wQDvM2iyI2wrNe468US1mHMjdJcKWGGvky4pMexIvmvmDsZLdsY");
		this.devicePrivateKey = (ECPrivateKey) KeyFactory.getInstance("EC").generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
	}

	@Test
	@DisplayName("decryptMasterkey(...)")
	public void testDecrypt() {
		String ephPk = "MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEkcv3x-hkCnb8Kr8TNfaLpD4q64ZqPn4p1yuM8r2r16h6f6mG01kFBp2EoY575bCcmT54PxiDFkf3KKqHXFjZwBhdm6zMp22l37ZlmKyHG96vkB7Rh6qFyzEhSQ_nvl2G";
		String ciphertext = "KQ48XS6ziW3tS7SMLR5sc2o_Y80OR4SS_htHpk8SHn4KrqI07EtDFFbNJ9AcNOazSu3TXrml--t_bEXprfnPqa3MlBvmPUVBcwUFJPDTR9Y";

// Path: src/main/java/org/cryptomator/cryptolib/api/Masterkey.java
// public class Masterkey extends DestroyableSecretKey {
// 
// 	private static final String KEY_ALGORITHM = "MASTERKEY";
// 	public static final String ENC_ALG = "AES";
// 	public static final String MAC_ALG = "HmacSHA256";
// 	public static final int SUBKEY_LEN_BYTES = 32;
// 
// 	public Masterkey(byte[] key) {
// 		super(checkKeyLength(key), KEY_ALGORITHM);
// 	}
// 
// 	private static byte[] checkKeyLength(byte[] key) {
// 		Preconditions.checkArgument(key.length == SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES, "Invalid raw key length %s", key.length);
// 		return key;
// 	}
// 
// 	public static Masterkey generate(SecureRandom csprng) {
// 		byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// 		try {
// 			csprng.nextBytes(key);
// 			return new Masterkey(key);
// 		} finally {
// 			Arrays.fill(key, (byte) 0x00);
// 		}
// 	}
// 
// 	public static Masterkey from(DestroyableSecretKey encKey, DestroyableSecretKey macKey) {
// 		Preconditions.checkArgument(encKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of encKey");
// 		Preconditions.checkArgument(macKey.getEncoded().length == SUBKEY_LEN_BYTES, "Invalid key length of macKey");
// 		byte[] key = new byte[SUBKEY_LEN_BYTES + SUBKEY_LEN_BYTES];
// 		try {
// 			System.arraycopy(encKey.getEncoded(), 0, key, 0, SUBKEY_LEN_BYTES);
// 			System.arraycopy(macKey.getEncoded(), 0, key, SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES);
// 			return new Masterkey(key);
// 		} finally {
// 			Arrays.fill(key, (byte) 0x00);
// 		}
// 	}
// 
// 	@Override
// 	public Masterkey copy() {
// 		return new Masterkey(getEncoded());
// 	}
// 
// 	/**
// 	 * Get the encryption subkey.
// 	 *
// 	 * @return A new copy of the subkey used for encryption
// 	 */
// 	public DestroyableSecretKey getEncKey() {
// 		return new DestroyableSecretKey(getEncoded(), 0, SUBKEY_LEN_BYTES, ENC_ALG);
// 	}
// 
// 	/**
// 	 * Get the MAC subkey.
// 	 *
// 	 * @return A new copy of the subkey used for message authentication
// 	 */
// 	public DestroyableSecretKey getMacKey() {
// 		return new DestroyableSecretKey(getEncoded(), SUBKEY_LEN_BYTES, SUBKEY_LEN_BYTES, MAC_ALG);
// 	}
// 
// }
// 
// Path: src/main/java/org/cryptomator/cryptolib/api/MasterkeyLoadingFailedException.java
// public class MasterkeyLoadingFailedException extends CryptoException {
// 
// 	public MasterkeyLoadingFailedException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public MasterkeyLoadingFailedException(String message) {
// 		super(message);
// 	}
// 
// }


// Path: src/test/java/org/cryptomator/cryptolib/common/MasterkeyHubAccessTest.java
import com.google.common.io.BaseEncoding;
import org.cryptomator.cryptolib.api.Masterkey;
import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.ECPrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Arrays;

package org.cryptomator.cryptolib.common;



public class MasterkeyHubAccessTest {

	private ECPrivateKey devicePrivateKey;

	@BeforeEach
	public void setup() throws NoSuchAlgorithmException, InvalidKeySpecException {
		byte[] keyBytes = BaseEncoding.base64Url().decode("ME4CAQAwEAYHKoZIzj0CAQYFK4EEACIENzA1AgEBBDDzj9mBnoqoYTO0wQDvM2iyI2wrNe468US1mHMjdJcKWGGvky4pMexIvmvmDsZLdsY");
		this.devicePrivateKey = (ECPrivateKey) KeyFactory.getInstance("EC").generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
	}

	@Test
	@DisplayName("decryptMasterkey(...)")
	public void testDecrypt() {
		String ephPk = "MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEkcv3x-hkCnb8Kr8TNfaLpD4q64ZqPn4p1yuM8r2r16h6f6mG01kFBp2EoY575bCcmT54PxiDFkf3KKqHXFjZwBhdm6zMp22l37ZlmKyHG96vkB7Rh6qFyzEhSQ_nvl2G";
		String ciphertext = "KQ48XS6ziW3tS7SMLR5sc2o_Y80OR4SS_htHpk8SHn4KrqI07EtDFFbNJ9AcNOazSu3TXrml--t_bEXprfnPqa3MlBvmPUVBcwUFJPDTR9Y";

		Masterkey masterkey = MasterkeyHubAccess.decryptMasterkey(devicePrivateKey, ciphertext, ephPk);