本文整理汇总了Java中java.util.Base64.getDecoder方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.getDecoder方法的具体用法?Java Base64.getDecoder怎么用?Java Base64.getDecoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Base64
的用法示例。
在下文中一共展示了Base64.getDecoder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decryptData_ECB
import java.util.Base64; //导入方法依赖的package包/类
public String decryptData_ECB(String cipherText) {
try {
SM4_Context ctx = new SM4_Context();
ctx.isPadding = true;
ctx.mode = SM4.SM4_DECRYPT;
byte[] keyBytes;
if (hexString) {
keyBytes = Util.hexStringToBytes(secretKey);
} else {
keyBytes = secretKey.getBytes();
}
SM4 sm4 = new SM4();
sm4.sm4_setkey_dec(ctx, keyBytes);
Base64.Decoder decoder = Base64.getDecoder();
byte[] decrypted = sm4.sm4_crypt_ecb(ctx, decoder.decode(cipherText));
return new String(decrypted, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例2: decryptData_CBC
import java.util.Base64; //导入方法依赖的package包/类
public String decryptData_CBC(String cipherText) {
try {
SM4_Context ctx = new SM4_Context();
ctx.isPadding = true;
ctx.mode = SM4.SM4_DECRYPT;
byte[] keyBytes;
byte[] ivBytes;
if (hexString) {
keyBytes = Util.hexStringToBytes(secretKey);
ivBytes = Util.hexStringToBytes(iv);
} else {
keyBytes = secretKey.getBytes();
ivBytes = iv.getBytes();
}
SM4 sm4 = new SM4();
sm4.sm4_setkey_dec(ctx, keyBytes);
Base64.Decoder decoder = Base64.getDecoder();
byte[] decrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, decoder.decode(cipherText));
return new String(decrypted, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例3: testDecodeUnpadded
import java.util.Base64; //导入方法依赖的package包/类
private static void testDecodeUnpadded() throws Throwable {
byte[] srcA = new byte[] { 'Q', 'Q' };
byte[] srcAA = new byte[] { 'Q', 'Q', 'E'};
Base64.Decoder dec = Base64.getDecoder();
byte[] ret = dec.decode(srcA);
if (ret[0] != 'A')
throw new RuntimeException("Decoding unpadding input A failed");
ret = dec.decode(srcAA);
if (ret[0] != 'A' && ret[1] != 'A')
throw new RuntimeException("Decoding unpadding input AA failed");
ret = new byte[10];
if (dec.wrap(new ByteArrayInputStream(srcA)).read(ret) != 1 &&
ret[0] != 'A')
throw new RuntimeException("Decoding unpadding input A from stream failed");
if (dec.wrap(new ByteArrayInputStream(srcA)).read(ret) != 2 &&
ret[0] != 'A' && ret[1] != 'A')
throw new RuntimeException("Decoding unpadding input AA from stream failed");
}
示例4: parseDerKeySpec
import java.util.Base64; //导入方法依赖的package包/类
public static DerKeySpec parseDerKeySpec(String rawKeyString) {
try {
// Base64 decode the data
Base64.Decoder b64decoder = Base64.getDecoder();
byte[] encoded =
b64decoder.decode(
rawKeyString
.replace("-----BEGIN RSA PRIVATE KEY-----\n", "")
.replace("-----END RSA PRIVATE KEY-----\n", "")
.replace("\n", ""));
DerInputStream derReader = new DerInputStream(encoded);
DerValue[] seq = derReader.getSequence(0);
if (seq.length != 9) {
throw new RuntimeException(
new GeneralSecurityException("Could not parse a PKCS1 private key."));
}
DerKeySpec ks = new DerKeySpec();
ks.version = seq[0].getBigInteger();
ks.modulus = seq[1].getBigInteger();
ks.publicExp = seq[2].getBigInteger();
ks.privateExp = seq[3].getBigInteger();
ks.prime1 = seq[4].getBigInteger();
ks.prime2 = seq[5].getBigInteger();
ks.exp1 = seq[6].getBigInteger();
ks.exp2 = seq[7].getBigInteger();
ks.crtCoef = seq[8].getBigInteger();
return ks;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例5: getObject
import java.util.Base64; //导入方法依赖的package包/类
public static byte[] getObject(DbfsClient client, String path) throws IOException, HttpException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
FileInfoDTO statusResponseDTO = client.getStatus(path);
long bytesLeftToRead = statusResponseDTO.FileSize;
long offset = 0;
while(bytesLeftToRead > 0) {
ReadResponseDTO readResponseDTO = client.read(path, offset, MAX_BLOCK_SIZE);
long numBytesRead = readResponseDTO.BytesRead;
//System.out.println("bytesLeftToRead: "+bytesLeftToRead + ", numBytesRead: "+numBytesRead);
Base64.Decoder decoder = Base64.getDecoder();
byte[] decodedBytes = decoder.decode(readResponseDTO.data);
outputStream.write(decodedBytes);
bytesLeftToRead = bytesLeftToRead - numBytesRead;
offset = offset + numBytesRead;
}
return outputStream.toByteArray();
} catch(Throwable e) {
throw e;
} finally {
outputStream.close();
}
}
示例6: createPublicKey
import java.util.Base64; //导入方法依赖的package包/类
static PublicKey createPublicKey(String modulus, String exponent) throws InvalidKeySpecException, NoSuchAlgorithmException
{
Base64.Decoder decoder = Base64.getDecoder();
BigInteger bigModulus = new BigInteger(1, decoder.decode(modulus));
BigInteger bigExponent = new BigInteger(1, decoder.decode(exponent));
RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(bigModulus, bigExponent);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePublic(publicKeySpec);
}
示例7: StaticKeySource
import java.util.Base64; //导入方法依赖的package包/类
StaticKeySource(final ClientSideStateProperties properties) {
final Decoder decoder = Base64.getDecoder();
final String encryptionKeyAlgorithm = properties.getEncryptionAlgorithm().replaceFirst("/.*", "");
encryptionKey = new SecretKeySpec(decoder.decode(properties.getEncryptionKey()), encryptionKeyAlgorithm);
authenticationKey = new SecretKeySpec(decoder.decode(properties.getAuthenticationKey()),
properties.getAuthenticationAlgorithm());
}
示例8: getPNGData
import java.util.Base64; //导入方法依赖的package包/类
private byte[] getPNGData(Picture picture, double width, double height) {
Base64.Decoder decoder = Base64.getDecoder();
byte[] decoded = decoder.decode(picture.getContent());
if (picture.getType() == ImageType.SVG) {
ByteArrayOutputStream pngStream = new ByteArrayOutputStream();
//svgConverter.convertSvgToPng(new ByteArrayInputStream(decoded), pngStream, (float)width, (float)height);
svgConverter.convertSvgToEmf(new ByteArrayInputStream(decoded), pngStream);
return pngStream.toByteArray();
} else {
return decoded;
}
}
示例9: main
import java.util.Base64; //导入方法依赖的package包/类
public static void main(String[] args){
KeyPairGenerator kpg = null;
try{
kpg = KeyPairGenerator.getInstance("RSA");
} catch(NoSuchAlgorithmException ex){
log.error(ex, ex);
throw new RuntimeException(ex);
}
kpg.initialize(1024);
KeyPair keyPair = kpg.generateKeyPair();
Key privateKey = keyPair.getPrivate();
Key publicKey = keyPair.getPublic();
Base64.Encoder encoder = Base64.getEncoder();
String privateKeyBase64Str = encoder.encodeToString(privateKey.getEncoded());
log.info("Private key in Base64 format:\n" + privateKeyBase64Str);//it creates 1623 chars or 1620 chars
Base64.Decoder decoder = Base64.getDecoder();
byte[] privateKeyBytes = decoder.decode(privateKeyBase64Str);
log.info("The private Key is " + privateKeyBytes.length + " bytes long");
String privateKeyHex = String.format("%040x", new BigInteger(1, privateKeyBytes));
log.info("The private key in hexadecimal digits:\n" + privateKeyHex);
String publicKeyBase64Str = encoder.encodeToString(publicKey.getEncoded());
log.info("Public key in Base64 format:\n" + publicKeyBase64Str);//it creates 392 chars and again 392 chars for 2048 bits
//it creates 162 bytes for 1024 bits, an Ethereum address is 20 bytes (40 hexadecimal digits/characters long)
//324 hexadecimal characters, and we use the last 40 as the Ethereum address
byte[] publicKeyBytes = decoder.decode(publicKeyBase64Str);
log.info("The public Key is " + publicKeyBytes.length + " bytes long");
String publicKeyHex = String.format("%040x", new BigInteger(1, publicKeyBytes));
log.info("The public key in hexadecimal digits:\n" + publicKeyHex);
}
示例10: decrypt
import java.util.Base64; //导入方法依赖的package包/类
public String decrypt(String encryptedText, String encryptedKey)throws Exception
{
Base64.Decoder decoder = Base64.getDecoder();
setSecretKey(new SecretKeySpec(decoder.decode(encryptedKey),0,decoder.decode(encryptedKey).length,"AES"));
byte [] encryptedTextByte = decoder.decode(encryptedText);
cpr.init(Cipher.DECRYPT_MODE, sk);
byte [] decryptedByte = cpr.doFinal(encryptedTextByte);
String decryptedText = new String(decryptedByte);
return (decryptedText);
}
示例11: getPermissions
import java.util.Base64; //导入方法依赖的package包/类
private static ArrayList<Permission> getPermissions(MySecureClassLoader scl,
Policy p, String url,
String className,
String classBytes,
Certificate[] chain)
throws IOException {
CodeSource cs = new CodeSource(new URL(url), chain);
Base64.Decoder bd = Base64.getDecoder();
byte[] bytes = bd.decode(classBytes);
Class<?> c = scl.defineMyClass(className, bytes, cs);
ProtectionDomain pd = c.getProtectionDomain();
return Collections.list(p.getPermissions(pd).elements());
}
示例12: testDecodeIgnoredAfterPadding
import java.util.Base64; //导入方法依赖的package包/类
private static void testDecodeIgnoredAfterPadding() throws Throwable {
for (byte nonBase64 : new byte[] {'#', '(', '!', '\\', '-', '_', '\n', '\r'}) {
byte[][] src = new byte[][] {
"A".getBytes("ascii"),
"AB".getBytes("ascii"),
"ABC".getBytes("ascii"),
"ABCD".getBytes("ascii"),
"ABCDE".getBytes("ascii")
};
Base64.Encoder encM = Base64.getMimeEncoder();
Base64.Decoder decM = Base64.getMimeDecoder();
Base64.Encoder enc = Base64.getEncoder();
Base64.Decoder dec = Base64.getDecoder();
for (int i = 0; i < src.length; i++) {
// decode(byte[])
byte[] encoded = encM.encode(src[i]);
encoded = Arrays.copyOf(encoded, encoded.length + 1);
encoded[encoded.length - 1] = nonBase64;
checkEqual(decM.decode(encoded), src[i], "Non-base64 char is not ignored");
byte[] decoded = new byte[src[i].length];
decM.decode(encoded, decoded);
checkEqual(decoded, src[i], "Non-base64 char is not ignored");
try {
dec.decode(encoded);
throw new RuntimeException("No IAE for non-base64 char");
} catch (IllegalArgumentException iae) {}
}
}
}
示例13: decrypt
import java.util.Base64; //导入方法依赖的package包/类
/**
* Decrypts password using secret key
* @param encryptedText
* @return
* @throws Exception
*/
public String decrypt(String encryptedText) throws Exception
{
logger.debug("Decryption algo running");
Cipher cipher = Cipher.getInstance(ALGO + "/" + MODE + "/" + PADDING);
cipher.init(Cipher.DECRYPT_MODE, key);
Base64.Decoder decoder = Base64.getDecoder();
byte[] decryptedByte = cipher.doFinal(decoder.decode(encryptedText));
String decryptedText = new String(decryptedByte);
logger.debug("Decryption algo executed");
return decryptedText;
}
示例14: modifyBytes
import java.util.Base64; //导入方法依赖的package包/类
public byte[] modifyBytes(byte[] input) throws ModificationException{
// Convert from Url safe
input = Utils.convertUrlBase64ToStandard(input);
try {
Base64.Decoder decoder = Base64.getDecoder();
return decoder.decode(input);
} catch (Exception e) {
throw new ModificationException("Invalid Base64 Input");
}
}
示例15: ExerciseRepository
import java.util.Base64; //导入方法依赖的package包/类
public ExerciseRepository(CypherQueryExecutor executor) {
this.executor = executor;
this.decoder = Base64.getDecoder();
}