本文整理汇总了Java中java.security.DigestException类的典型用法代码示例。如果您正苦于以下问题:Java DigestException类的具体用法?Java DigestException怎么用?Java DigestException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DigestException类属于java.security包,在下文中一共展示了DigestException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SHA1
import java.security.DigestException; //导入依赖的package包/类
public static String SHA1(String decrypt) throws DigestException {
//获取信息摘要 - 参数字典排序后字符串
try {
//指定sha1算法
MessageDigest digest = MessageDigest
.getInstance("SHA-1");
digest.update(decrypt.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuilder hexString = new StringBuilder();
// 字节数组转换为 十六进制 数
for (byte aMessageDigest : messageDigest) {
String shaHex = Integer.toHexString(aMessageDigest & 0xFF);
if (shaHex.length() < 2) {
hexString.append(0);
}
hexString.append(shaHex);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new DigestException("签名错误!");
}
}
示例2: testPull
import java.security.DigestException; //导入依赖的package包/类
@Test
public void testPull() throws IOException, RegistryException, DigestException {
// Pulls the busybox image.
RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "busybox");
V21ManifestTemplate manifestTemplate =
registryClient.pullManifest("latest", V21ManifestTemplate.class);
DescriptorDigest realDigest = manifestTemplate.getLayerDigests().get(0);
// Pulls a layer BLOB of the busybox image.
Path destFile = temporaryFolder.newFile().toPath();
Path checkBlobFile = temporaryFolder.newFile().toPath();
Blob blob = registryClient.pullBlob(realDigest, destFile);
try (OutputStream outputStream =
new BufferedOutputStream(Files.newOutputStream(checkBlobFile))) {
BlobDescriptor blobDescriptor = blob.writeTo(outputStream);
Assert.assertEquals(realDigest, blobDescriptor.getDigest());
}
Assert.assertArrayEquals(Files.readAllBytes(destFile), Files.readAllBytes(checkBlobFile));
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:24,代码来源:BlobPullerIntegrationTest.java
示例3: testPull_unknownBlob
import java.security.DigestException; //导入依赖的package包/类
@Test
public void testPull_unknownBlob() throws RegistryException, IOException, DigestException {
DescriptorDigest nonexistentDigest =
DescriptorDigest.fromHash(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
try {
RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "busybox");
registryClient.pullBlob(nonexistentDigest, Mockito.mock(Path.class));
Assert.fail("Trying to pull nonexistent blob should have errored");
} catch (RegistryErrorException ex) {
Assert.assertThat(
ex.getMessage(),
CoreMatchers.containsString(
"pull BLOB for localhost:5000/busybox with digest " + nonexistentDigest));
}
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:19,代码来源:BlobPullerIntegrationTest.java
示例4: test_smokeTest
import java.security.DigestException; //导入依赖的package包/类
@Test
public void test_smokeTest() throws IOException, DigestException {
for (Map.Entry<String, String> knownHash : knownSha256Hashes.entrySet()) {
String toHash = knownHash.getKey();
String expectedHash = knownHash.getValue();
OutputStream underlyingOutputStream = new ByteArrayOutputStream();
CountingDigestOutputStream countingDigestOutputStream =
new CountingDigestOutputStream(underlyingOutputStream);
byte[] bytesToHash = toHash.getBytes(StandardCharsets.UTF_8);
InputStream toHashInputStream = new ByteArrayInputStream(bytesToHash);
ByteStreams.copy(toHashInputStream, countingDigestOutputStream);
BlobDescriptor expectedBlobDescriptor =
new BlobDescriptor(bytesToHash.length, DescriptorDigest.fromHash(expectedHash));
Assert.assertEquals(expectedBlobDescriptor, countingDigestOutputStream.toBlobDescriptor());
Assert.assertEquals(bytesToHash.length, countingDigestOutputStream.getTotalBytes());
}
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:21,代码来源:CountingDigestOutputStreamTest.java
示例5: setUp
import java.security.DigestException; //导入依赖的package包/类
@Before
public void setUp() throws DigestException {
baseLayerBlobDescriptor =
new BlobDescriptor(
631,
DescriptorDigest.fromDigest(
"sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"));
baseLayerDiffId =
DescriptorDigest.fromDigest(
"sha256:b56ae66c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a4647");
classesLayerBlobDescriptor =
new BlobDescriptor(
223,
DescriptorDigest.fromDigest(
"sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"));
classesLayerDiffId =
DescriptorDigest.fromDigest(
"sha256:a3f3e99c29370df48e7377c8f9baa744a3958058a766793f821dadcb144a8372");
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:20,代码来源:CacheMetadataTranslatorTest.java
示例6: testGetLayerFile
import java.security.DigestException; //导入依赖的package包/类
@Test
public void testGetLayerFile() throws DigestException {
DescriptorDigest layerDigest =
DescriptorDigest.fromDigest(
"sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad");
ArgumentCaptor<String> fileNameCaptor = ArgumentCaptor.forClass(String.class);
Mockito.when(mockPath.resolve(fileNameCaptor.capture())).thenReturn(mockPath);
Path layerFile = CacheFiles.getLayerFile(mockPath, layerDigest);
Assert.assertEquals(
"8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad.tar.gz",
fileNameCaptor.getValue());
Assert.assertEquals(mockPath, layerFile);
}
示例7: testToJson
import java.security.DigestException; //导入依赖的package包/类
@Test
public void testToJson() throws IOException, URISyntaxException, DigestException {
// Loads the expected JSON string.
Path jsonFile = Paths.get(Resources.getResource("json/containerconfig.json").toURI());
String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
// Creates the JSON object to serialize.
ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate();
containerConfigJson.setContainerEnvironment(Arrays.asList("VAR1=VAL1", "VAR2=VAL2"));
containerConfigJson.setContainerEntrypoint(Arrays.asList("some", "entrypoint", "command"));
containerConfigJson.addLayerDiffId(
DescriptorDigest.fromDigest(
"sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"));
// Serializes the JSON object.
ByteArrayOutputStream jsonStream = new ByteArrayOutputStream();
JsonTemplateMapper.writeJson(jsonStream, containerConfigJson);
Assert.assertEquals(expectedJson, jsonStream.toString());
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:23,代码来源:ContainerConfigurationTemplateTest.java
示例8: testFromJson
import java.security.DigestException; //导入依赖的package包/类
@Test
public void testFromJson() throws IOException, URISyntaxException, DigestException {
// Loads the JSON string.
Path jsonFile = Paths.get(Resources.getResource("json/containerconfig.json").toURI());
// Deserializes into a manifest JSON object.
ContainerConfigurationTemplate containerConfigJson =
JsonTemplateMapper.readJsonFromFile(jsonFile, ContainerConfigurationTemplate.class);
Assert.assertEquals(
Arrays.asList("VAR1=VAL1", "VAR2=VAL2"), containerConfigJson.getContainerEnvironment());
Assert.assertEquals(
Arrays.asList("some", "entrypoint", "command"),
containerConfigJson.getContainerEntrypoint());
Assert.assertEquals(
DescriptorDigest.fromDigest(
"sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"),
containerConfigJson.getLayerDiffId(0));
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:22,代码来源:ContainerConfigurationTemplateTest.java
示例9: testToJson
import java.security.DigestException; //导入依赖的package包/类
@Test
public void testToJson() throws DigestException, IOException, URISyntaxException {
// Loads the expected JSON string.
Path jsonFile = Paths.get(Resources.getResource("json/v22manifest.json").toURI());
String expectedJson = new String(Files.readAllBytes(jsonFile), StandardCharsets.UTF_8);
// Creates the JSON object to serialize.
V22ManifestTemplate manifestJson = new V22ManifestTemplate();
manifestJson.setContainerConfiguration(
1000,
DescriptorDigest.fromDigest(
"sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"));
manifestJson.addLayer(
1000_000,
DescriptorDigest.fromHash(
"4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236"));
// Serializes the JSON object.
ByteArrayOutputStream jsonStream = new ByteArrayOutputStream();
JsonTemplateMapper.writeJson(jsonStream, manifestJson);
Assert.assertEquals(expectedJson, jsonStream.toString());
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:26,代码来源:V22ManifestTemplateTest.java
示例10: testFromJson
import java.security.DigestException; //导入依赖的package包/类
@Test
public void testFromJson() throws IOException, URISyntaxException, DigestException {
// Loads the JSON string.
Path jsonFile = Paths.get(Resources.getResource("json/v22manifest.json").toURI());
// Deserializes into a manifest JSON object.
V22ManifestTemplate manifestJson =
JsonTemplateMapper.readJsonFromFile(jsonFile, V22ManifestTemplate.class);
Assert.assertEquals(
DescriptorDigest.fromDigest(
"sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"),
manifestJson.getContainerConfigurationDigest());
Assert.assertEquals(1000, manifestJson.getContainerConfigurationSize());
Assert.assertEquals(
DescriptorDigest.fromHash(
"4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236"),
manifestJson.getLayerDigest(0));
Assert.assertEquals(1000_000, manifestJson.getLayerSize(0));
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:24,代码来源:V22ManifestTemplateTest.java
示例11: setUp
import java.security.DigestException; //导入依赖的package包/类
@Before
public void setUp()
throws DigestException, LayerPropertyNotFoundException, DuplicateLayerException {
Image testImage = new Image();
testImage.setEnvironmentVariable("VAR1", "VAL1");
testImage.setEnvironmentVariable("VAR2", "VAL2");
testImage.setEntrypoint(Arrays.asList("some", "entrypoint", "command"));
DescriptorDigest fakeDigest =
DescriptorDigest.fromDigest(
"sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad");
Layer fakeLayer = new ReferenceLayer(new BlobDescriptor(1000, fakeDigest), fakeDigest);
testImage.addLayer(fakeLayer);
imageToJsonTranslator = new ImageToJsonTranslator(testImage);
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:19,代码来源:ImageToJsonTranslatorTest.java
示例12: testFromJson
import java.security.DigestException; //导入依赖的package包/类
@Test
public void testFromJson() throws URISyntaxException, IOException, DigestException {
// Loads the JSON string.
Path jsonFile = Paths.get(Resources.getResource("json/v21manifest.json").toURI());
// Deserializes into a manifest JSON object.
V21ManifestTemplate manifestJson =
JsonTemplateMapper.readJsonFromFile(jsonFile, V21ManifestTemplate.class);
Assert.assertEquals(
DescriptorDigest.fromDigest(
"sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"),
manifestJson.getLayerDigest(0));
Assert.assertEquals("some v1-compatible object", manifestJson.getV1Compatibility(0));
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:17,代码来源:V21ManifestTemplateTest.java
示例13: testToImage_v21
import java.security.DigestException; //导入依赖的package包/类
@Test
public void testToImage_v21()
throws IOException, LayerPropertyNotFoundException, DuplicateLayerException, DigestException,
URISyntaxException {
// Loads the JSON string.
Path jsonFile =
Paths.get(getClass().getClassLoader().getResource("json/v21manifest.json").toURI());
// Deserializes into a manifest JSON object.
V21ManifestTemplate manifestTemplate =
JsonTemplateMapper.readJsonFromFile(jsonFile, V21ManifestTemplate.class);
Image image = JsonToImageTranslator.toImage(manifestTemplate);
List<Layer> layers = image.getLayers();
Assert.assertEquals(1, layers.size());
Assert.assertEquals(
DescriptorDigest.fromDigest(
"sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"),
layers.get(0).getBlobDescriptor().getDigest());
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:22,代码来源:JsonToImageTranslatorTest.java
示例14: setLessInstances
import java.security.DigestException; //导入依赖的package包/类
protected void setLessInstances(String key,
String format,
String fileName,
String sourceName,
String sourcePath) throws InterruptedException, IOException, NoSuchAlgorithmException, DigestException {
setPxInstance(key,
"500",
format,
fileName,
sourceName,
sourcePath);
setPxInstance(key,
"400",
format,
fileName,
sourceName,
sourcePath);
setPxInstance(key,
"200",
format,
fileName,
sourceName,
sourcePath);
}
示例15: getSubDirForZip
import java.security.DigestException; //导入依赖的package包/类
private File getSubDirForZip(String[] tokens, String baseZipUrl, String baseSubDir) throws CantLoadMCPMappingException, NoSuchAlgorithmException, DigestException, IOException
{
if (!baseDir.exists() && !baseDir.mkdirs())
throw new CantLoadMCPMappingException("Application data folder does not exist and cannot be created.");
File subDir = new File(baseDir, replaceTokens(baseSubDir, tokens));
if (!subDir.exists() && !subDir.mkdirs())
throw new CantLoadMCPMappingException("Data folder does not exist and cannot be created.");
try {
RemoteZipHandler rzh = new RemoteZipHandler(replaceTokens(baseZipUrl, tokens), subDir, "SHA1");
rzh.checkRemoteZip();
} catch (Throwable t) {
ASMStackLogger.printStackTrace(t);
}
return subDir;
}