当前位置: 首页>>代码示例>>Java>>正文


Java KMSRESTConstants.EEK_DECRYPT属性代码示例

本文整理汇总了Java中org.apache.hadoop.crypto.key.kms.KMSRESTConstants.EEK_DECRYPT属性的典型用法代码示例。如果您正苦于以下问题:Java KMSRESTConstants.EEK_DECRYPT属性的具体用法?Java KMSRESTConstants.EEK_DECRYPT怎么用?Java KMSRESTConstants.EEK_DECRYPT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.hadoop.crypto.key.kms.KMSRESTConstants的用法示例。


在下文中一共展示了KMSRESTConstants.EEK_DECRYPT属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decryptEncryptedKey

@SuppressWarnings("rawtypes")
@POST
@Path(KMSRESTConstants.KEY_VERSION_RESOURCE + "/{versionName:.*}/" +
    KMSRESTConstants.EEK_SUB_RESOURCE)
@Produces(MediaType.APPLICATION_JSON)
public Response decryptEncryptedKey(
    @PathParam("versionName") final String versionName,
    @QueryParam(KMSRESTConstants.EEK_OP) String eekOp,
    Map jsonPayload)
    throws Exception {
  UserGroupInformation user = HttpUserGroupInformation.get();
  KMSClientProvider.checkNotEmpty(versionName, "versionName");
  KMSClientProvider.checkNotNull(eekOp, "eekOp");

  final String keyName = (String) jsonPayload.get(
      KMSRESTConstants.NAME_FIELD);
  String ivStr = (String) jsonPayload.get(KMSRESTConstants.IV_FIELD);
  String encMaterialStr = 
      (String) jsonPayload.get(KMSRESTConstants.MATERIAL_FIELD);
  Object retJSON;
  if (eekOp.equals(KMSRESTConstants.EEK_DECRYPT)) {
    assertAccess(KMSACLs.Type.DECRYPT_EEK, user, KMSOp.DECRYPT_EEK, keyName);
    KMSClientProvider.checkNotNull(ivStr, KMSRESTConstants.IV_FIELD);
    final byte[] iv = Base64.decodeBase64(ivStr);
    KMSClientProvider.checkNotNull(encMaterialStr,
        KMSRESTConstants.MATERIAL_FIELD);
    final byte[] encMaterial = Base64.decodeBase64(encMaterialStr);

    KeyProvider.KeyVersion retKeyVersion = user.doAs(
        new PrivilegedExceptionAction<KeyVersion>() {
          @Override
          public KeyVersion run() throws Exception {
            return provider.decryptEncryptedKey(
                new KMSClientProvider.KMSEncryptedKeyVersion(keyName,
                    versionName, iv, KeyProviderCryptoExtension.EEK,
                    encMaterial)
            );
          }
        }
    );

    retJSON = KMSServerJSONUtils.toJSON(retKeyVersion);
    kmsAudit.ok(user, KMSOp.DECRYPT_EEK, keyName, "");
  } else {
    throw new IllegalArgumentException("Wrong " + KMSRESTConstants.EEK_OP +
        " value, it must be " + KMSRESTConstants.EEK_GENERATE + " or " +
        KMSRESTConstants.EEK_DECRYPT);
  }
  KMSWebApp.getDecryptEEKCallsMeter().mark();
  return Response.ok().type(MediaType.APPLICATION_JSON).entity(retJSON)
      .build();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:52,代码来源:KMS.java

示例2: generateEncryptedKeys

@SuppressWarnings({ "rawtypes", "unchecked" })
@GET
@Path(KMSRESTConstants.KEY_RESOURCE + "/{name:.*}/" +
    KMSRESTConstants.EEK_SUB_RESOURCE)
@Produces(MediaType.APPLICATION_JSON)
public Response generateEncryptedKeys(
        @PathParam("name") final String name,
        @QueryParam(KMSRESTConstants.EEK_OP) String edekOp,
        @DefaultValue("1")
        @QueryParam(KMSRESTConstants.EEK_NUM_KEYS) final int numKeys)
        throws Exception {
  UserGroupInformation user = HttpUserGroupInformation.get();
  KMSClientProvider.checkNotEmpty(name, "name");
  KMSClientProvider.checkNotNull(edekOp, "eekOp");

  Object retJSON;
  if (edekOp.equals(KMSRESTConstants.EEK_GENERATE)) {
    assertAccess(KMSACLs.Type.GENERATE_EEK, user, KMSOp.GENERATE_EEK, name);

    final List<EncryptedKeyVersion> retEdeks =
        new LinkedList<EncryptedKeyVersion>();
    try {

      user.doAs(
          new PrivilegedExceptionAction<Void>() {
            @Override
            public Void run() throws Exception {
              for (int i = 0; i < numKeys; i++) {
                retEdeks.add(provider.generateEncryptedKey(name));
              }
              return null;
            }
          }
      );

    } catch (Exception e) {
      throw new IOException(e);
    }
    kmsAudit.ok(user, KMSOp.GENERATE_EEK, name, "");
    retJSON = new ArrayList();
    for (EncryptedKeyVersion edek : retEdeks) {
      ((ArrayList)retJSON).add(KMSServerJSONUtils.toJSON(edek));
    }
  } else {
    throw new IllegalArgumentException("Wrong " + KMSRESTConstants.EEK_OP +
        " value, it must be " + KMSRESTConstants.EEK_GENERATE + " or " +
        KMSRESTConstants.EEK_DECRYPT);
  }
  KMSWebApp.getGenerateEEKCallsMeter().mark();
  return Response.ok().type(MediaType.APPLICATION_JSON).entity(retJSON)
      .build();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:52,代码来源:KMS.java


注:本文中的org.apache.hadoop.crypto.key.kms.KMSRESTConstants.EEK_DECRYPT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。