Converter um clientecret em uma chave privada

Estou trabalhando com o Google Cloud Storage no AppEngine e estou tentando usar um formulário POST para fazer upload de um arquivo para o GCS. O problema que estou tendo é com as etapas necessárias para assinar o documento de política. Eu posso facilmente buscar o client_secret, que é uma String doclient_secrets.json que a API Console me deu. no entanto, a fim de criar uma assinatura, eu preciso converter essa seqüência em umPrivateKey objeto. Aqui está o meu código:

//create the policy document and encode it
String policyDocument = ...  //omitted for brevity
String encodedPolicy = Base64.encodeString(policyDocument);

//sign using SHA256 with RSA
String secretKey = ... //I fetch this from client_secrets.json
Signature sig = Signature.getInstance("SHA256withRSA");
sig.initSign(secretKey); //THIS IS THE PROBLEM!  
sig.update(encodedPolicy.getBytes("UTF-8"));        
String signature = new String(Base64.encode(sig.sign()));

//put the values in the request attributes so we can fetch them from a JSP
req.setAttribute("policy", encodedPolicy);
req.setAttribute("signature", signature);

Como mencionado acima, meu problema está na linha

sig.initSign(secretKey); //THIS IS THE PROBLEM!  

secretKey é uma string.Signature.initSign() espera umPrivateKeyou um de seus objetos descendentes. Como faço para converter a string noclient_secrets.json em um objeto PrivateKey (ou derivado) que eu posso passarSignature.initSign?

Qualquer ajuda seria muito apreciada. obrigado

OK, aqui é onde eu estou agora. Eu tentei as sugestões abaixo, e toda a documentação está me incentivando a usar o client_secret no arquivo client_secrets.json baixado do console da API do Google,não a conta de serviço. Além disso, estou tentando construir um exemplo de upload de um usuário, não uma conta de serviço.

Eu encontrei o seguinte código em outra página:

public static String signPolicyDocument(String policyDocument, String secret) {     
try {
        Mac mac = Mac.getInstance("HmacSHA256");
        byte[] secretBytes = secret.getBytes();
        SecretKeySpec signingKey = new SecretKeySpec(secretBytes, "HmacSHA256");
        mac.init(signingKey);
        byte[] signedSecretBytes = mac.doFinal(policyDocument.getBytes());          
        return new String(Base64.encode(signedSecretBytes));
    } catch (InvalidKeyException e) {
        throw new RuntimeException(e);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }

E isso me leva ao longo do processo ... até que eu envie o formulário resultante. Então recebo a seguinte resposta:

The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.

Qual método de assinatura está procurando?

questionAnswers(3)

yourAnswerToTheQuestion