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


Java BaseEncoding类代码示例

本文整理汇总了Java中com.google.common.io.BaseEncoding的典型用法代码示例。如果您正苦于以下问题:Java BaseEncoding类的具体用法?Java BaseEncoding怎么用?Java BaseEncoding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: decode

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
public static Schema decode(String schemaName, String[] compressedFragments) {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        for (String part : compressedFragments) {
            bos.write(BaseEncoding.base64Url().decode(part));
        }
        bos.flush();
        try (ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray())) {
            try (InflaterInputStream in = new InflaterInputStream(bin)) {
                byte[] allBinary = ByteStreams.toByteArray(in);
                String all = new String(allBinary, StandardCharsets.UTF_8);
                return new Parser()
                        .parse(all)
                        .getSchema(schemaName);
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:atlascon,项目名称:travny,代码行数:20,代码来源:SchemaDecoder.java

示例2: build

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
String build() {
  try {
    bytes = new ByteArrayOutputStream();
    out = new ObjectOutputStream(bytes);

    // We will generate SHA-1 hash of the call site information based on call site
    // attributes used in equality comparison, such that if the two call sites are
    // different their hashes should also be different.
    write(methodName);
    write(methodProto);
    write(bootstrapMethod);
    write(bootstrapArgs);
    out.close();

    MessageDigest digest = MessageDigest.getInstance("SHA-1");
    digest.update(bytes.toByteArray());
    return BaseEncoding.base64Url().omitPadding().encode(digest.digest());
  } catch (NoSuchAlgorithmException | IOException ex) {
    throw new Unreachable("Cannot get SHA-1 message digest");
  }
}
 
开发者ID:inferjay,项目名称:r8,代码行数:22,代码来源:DexCallSite.java

示例3: onLogin

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
@Override
public CompletableFuture<Long> onLogin(ChannelHandlerContext ctx, SocketASK ask) {
    // 整个消息就是 token
    ByteString tokenArg = ask.getBody().getArgs(0);
    if (tokenArg == null) {
        logger.info("Token arg must be input.");
        return null;
    }
    String token = tokenArg.toStringUtf8();
    if (Strings.isNullOrEmpty(token)) {
        logger.info("Token arg must be input.");
        return null;
    }
    return CompletableFuture.supplyAsync(() -> {
        String parseToken = new String(BaseEncoding.base64Url().decode(token));
        List<String> tokenChars = Splitter.on('|').splitToList(parseToken);
        return Long.valueOf(tokenArg.toStringUtf8());
    });
}
 
开发者ID:freedompy,项目名称:commelina,代码行数:20,代码来源:NioSocketEventHandlerForAkka.java

示例4: onLogin

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
@Override
public CompletableFuture<Long> onLogin(ChannelHandlerContext ctx, SocketASK ask) {
    // 整个消息就是 token
    ByteString tokenArg = ask.getBody().getArgs(0);
    if (tokenArg == null) {
        logger.info("Token arg must be input.");
        return null;
    }
    String token = tokenArg.toStringUtf8();
    if (Strings.isNullOrEmpty(token)) {
        logger.info("Token arg must be input.");
        return null;
    }
    return CompletableFuture.supplyAsync(() -> {
        String parseToken = new String(BaseEncoding.base64Url().decode(token));
        List<String> tokenChars = Splitter.on('|').splitToList(parseToken);

        Long userId = Long.valueOf(tokenArg.toStringUtf8());
        RoomGroup.getRoomManger().onOnline(ctx, userId);
        return userId;
    });
}
 
开发者ID:freedompy,项目名称:commelina,代码行数:23,代码来源:NioSocketEventHandler.java

示例5: createResponseMap

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
@NonNull
private Map<String, Object> createResponseMap(Parcel reply) {
    Map<String, Object> data = new HashMap<>();
    data.put("message", "reply");
    if (reply != null) {
        try {
            byte[] marshalled = reply.marshall();
            data.put("data", marshalled);
            if (marshalled != null) {
                String base64 = BaseEncoding.base64().encode(marshalled).replace("/", "");
                data.put("data_base64", base64);
            }
        } catch (RuntimeException e) {
            data.put("info", "activeObject");
        }
    }
    return data;
}
 
开发者ID:mateuszk87,项目名称:BadIntent,代码行数:19,代码来源:RestAPI.java

示例6: deserializeItemStack

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
public static ItemStack deserializeItemStack(String itemStackString) {
    if (itemStackString == null || itemStackString.length() == 0 || itemStackString.equals("null"))
        return null;

    ByteArrayInputStream inputStream = new ByteArrayInputStream(BaseEncoding.base64().decode(itemStackString));
    NBTTagCompound tagComp;
    try {
        tagComp = NBTCompressedStreamTools.a(inputStream);
        net.minecraft.server.v1_10_R1.ItemStack item = net.minecraft.server.v1_10_R1.ItemStack.createStack(tagComp);
        ItemStack bukkitItem = CraftItemStack.asBukkitCopy(item);
        return bukkitItem;
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}
 
开发者ID:edasaki,项目名称:ZentrelaCore,代码行数:18,代码来源:RSerializer.java

示例7: doFilter

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
	// retrieve userId and set
	if (request instanceof HttpServletRequest) {
		Principal principal = ((HttpServletRequest) request).getUserPrincipal();
		if (principal != null) {
			String ppal = principal.getName();
			if (hashAlgorithm == null || "none".equalsIgnoreCase(hashAlgorithm)) {
				// no hash
			} else if ("hashcode".equalsIgnoreCase(hashAlgorithm)) {
				// simply hashcode
				ppal = Strings.padStart(Integer.toHexString(ppal.hashCode()), 8, '0');
			} else {
				// hexadecimal hash
				try {
					MessageDigest digest = MessageDigest.getInstance(hashAlgorithm);
					ppal = BaseEncoding.base16().encode(digest.digest(ppal.getBytes()));
				} catch (NoSuchAlgorithmException e) {
					throw new ServletException(e);
				}
			}
			// add to MDC and request attribute
			MDC.put(mdcName, ppal);
			request.setAttribute(attributeName, ppal);
		}
	}

	try {
		chain.doFilter(request, response);
	} finally {
		MDC.remove(mdcName);
	}
}
 
开发者ID:Orange-OpenSource,项目名称:orange-mathoms-logging,代码行数:33,代码来源:PrincipalFilter.java

示例8: afterPropertiesSet

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
public void afterPropertiesSet() throws UnsupportedEncodingException {
  Collection<Header> defaultHeaders = new ArrayList<Header>();
  Header header = new BasicHeader("Authorization",
      "Basic " + BaseEncoding.base64().encode("apollo:".getBytes("UTF-8")));
  defaultHeaders.add(header);

  BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
  credentialsProvider.setCredentials(AuthScope.ANY,
      new UsernamePasswordCredentials("apollo", ""));
  CloseableHttpClient httpClient =
      HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider)
          .setDefaultHeaders(defaultHeaders).build();


  restTemplate = new RestTemplate(httpMessageConverters.getConverters());
  HttpComponentsClientHttpRequestFactory requestFactory =
      new HttpComponentsClientHttpRequestFactory(httpClient);
  requestFactory.setConnectTimeout(portalConfig.connectTimeout());
  requestFactory.setReadTimeout(portalConfig.readTimeout());

  restTemplate.setRequestFactory(requestFactory);
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:23,代码来源:RestTemplateFactory.java

示例9: getCertificateThumbprint

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
private String getCertificateThumbprint(String pfxPath, String password) {
    try {
        InputStream inStream = new FileInputStream(pfxPath);

        KeyStore ks = KeyStore.getInstance("PKCS12");
        ks.load(inStream, password.toCharArray());

        String alias = ks.aliases().nextElement();
        X509Certificate certificate = (X509Certificate) ks.getCertificate(alias);
        inStream.close();
        MessageDigest sha = MessageDigest.getInstance("SHA-1");
        return BaseEncoding.base16().encode(sha.digest(certificate.getEncoded()));
    } catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | IOException ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:17,代码来源:HostNameSslBindingImpl.java

示例10: AuthenticatorAssertionResponse

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
/**
 * @param data
 * @throws ResponseException
 */
public AuthenticatorAssertionResponse(JsonElement data) throws ResponseException {
  Gson gson = new Gson();
  try {
    AssertionResponseJson parsedObject = gson.fromJson(data, AssertionResponseJson.class);
    clientDataBytes = BaseEncoding.base64().decode(parsedObject.clientDataJSON);
    clientData = gson.fromJson(new String(clientDataBytes), CollectedClientData.class);

    authDataBytes = BaseEncoding.base64().decode(parsedObject.authenticatorData);
    authData =
        AuthenticatorData.decode(authDataBytes);
    signature = BaseEncoding.base64().decode(parsedObject.signature);
    userHandle = BaseEncoding.base64().decode(parsedObject.userHandle);
  } catch (JsonSyntaxException e) {
    throw new ResponseException("Response format incorrect");
  }
}
 
开发者ID:google,项目名称:webauthndemo,代码行数:21,代码来源:AuthenticatorAssertionResponse.java

示例11: AuthenticatorAttestationResponse

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
/**
 * @param data
 * @throws ResponseException
 */
public AuthenticatorAttestationResponse(JsonElement data) throws ResponseException {
  Gson gson = new Gson();
  AttestationResponseJson parsedObject = gson.fromJson(data, AttestationResponseJson.class);

  clientDataBytes = BaseEncoding.base64().decode(parsedObject.clientDataJSON);
  byte[] attestationObject = BaseEncoding.base64().decode(parsedObject.attestationObject);

  try {
    decodedObject = AttestationObject.decode(attestationObject);
  } catch (CborException e) {
    throw new ResponseException("Cannot decode attestation object");
  }

  clientData = gson.fromJson(new String(clientDataBytes), CollectedClientData.class);
}
 
开发者ID:google,项目名称:webauthndemo,代码行数:20,代码来源:AuthenticatorAttestationResponse.java

示例12: getJsonObject

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
/**
 * @return Encoded JsonObject representation of PublicKeyCredentialDescriptor
 */
public JsonObject getJsonObject() {
  JsonObject result = new JsonObject();
  result.addProperty("type", type.toString());

  result.addProperty("id", BaseEncoding.base64().encode(id));
  JsonArray transports = new JsonArray();
  if (this.transports != null) {
    for (AuthenticatorTransport t : this.transports) {
      JsonPrimitive element = new JsonPrimitive(t.toString());
      transports.add(element);
    }
    if (transports.size() > 0) {
      result.add("transports", transports);
    }
  }

  return result;
}
 
开发者ID:google,项目名称:webauthndemo,代码行数:22,代码来源:PublicKeyCredentialDescriptor.java

示例13: getJsonObject

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
/**
 * @return JsonObject representation of PublicKeyCredentialRequestOptions
 */
public JsonObject getJsonObject() {
  JsonObject result = new JsonObject();

  result.addProperty("challenge", BaseEncoding.base64().encode(challenge));
  if (timeout > 0) {
    result.addProperty("timeout", timeout);
  }
  result.addProperty("rpId", rpId);
  JsonArray allowList = new JsonArray();
  for (PublicKeyCredentialDescriptor credential : this.allowCredentials) {
    allowList.add(credential.getJsonObject());
  }
  result.add("allowList", allowList);

  return result;
}
 
开发者ID:google,项目名称:webauthndemo,代码行数:20,代码来源:PublicKeyCredentialRequestOptions.java

示例14: testConstructionUsingMultipleThreads

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
/**
 * Tests concurrently creating an instance of {@link PreimageSha256Condition}. This test validates
 * the fix for Github issue #40 where construction of this class was not thread-safe.
 *
 * @see "https://github.com/interledger/java-crypto-conditions/issues/40"
 * @see "https://github.com/junit-team/junit4/wiki/multithreaded-code-and-concurrency"
 */
@Test
public void testConstructionUsingMultipleThreads() throws Exception {
  final Runnable runnableTest = () -> {
    final PreimageSha256Condition condition = new PreimageSha256Condition(PREIMAGE.getBytes());

    assertThat(condition.getType(), is(CryptoConditionType.PREIMAGE_SHA256));
    assertThat(condition.getCost(), is(3L));
    assertThat(CryptoConditionUri.toUri(condition), is(CONDITION_URI));

    assertThat(BaseEncoding.base64().encode(condition.getFingerprint()),
        is("mDSHbc+wXLFnpcJJU+uljErImxrfV/KPL50JrxB+6PA="));
    assertThat(
        BaseEncoding.base64().encode(condition.constructFingerprintContents(PREIMAGE.getBytes())),
        is("YWFh"));
  };

  this.runConcurrent(1, runnableTest);
  this.runConcurrent(runnableTest);
}
 
开发者ID:hyperledger,项目名称:quilt,代码行数:27,代码来源:PreimageSha256ConditionTest.java

示例15: testSignsCorrectly

import com.google.common.io.BaseEncoding; //导入依赖的package包/类
/**
 * This test ensures that the supplied private key signs a message correctly.
 */
@Test
public void testSignsCorrectly() throws Exception {

  final String privKeyPem = rsaJsonTestVector.getPrivateKey();
  final RSAPrivateKey privKey = this.buildRsaPrivKey(privKeyPem);

  rsaJsonTestVector.getCases().stream().forEach(_case -> {
    try {
      final byte[] saltHex = BaseEncoding.base16().decode(_case.getSalt().toUpperCase());
      rsaSigner.initSign(privKey, new FixedRandom(saltHex));
      rsaSigner.update(BaseEncoding.base16().decode(_case.getMessage().toUpperCase()));
      byte[] rsaSignature = rsaSigner.sign();

      assertThat(_case.getSignature().toUpperCase(),
          is(BaseEncoding.base16().encode(rsaSignature)));
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  });
}
 
开发者ID:hyperledger,项目名称:quilt,代码行数:24,代码来源:RsaSha256SignatureTest.java


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