使用するモジュール
use MIME::Base64;
perl -MMIME::Base64 -ne 'print decode_base64($_)'
< くっつけたBase64ファイル名.txt > 出力ファイル名.pdf
(上は、すべて1行に書く)
使用するモジュール
use MIME::Base64;
perl -MMIME::Base64 -ne 'print decode_base64($_)'
< くっつけたBase64ファイル名.txt > 出力ファイル名.pdf
(上は、すべて1行に書く)
import java.security.*;
...
public final static String RANDOM_ALGORITHM = "SHA1PRNG";
public final static int RANDOM_LENGTH = 16;
...
public byte[] getRandom() {
try {
SecureRandom random = SecureRandom.getInstance(RANDOM_ALGORITHM);
byte seed[] = random.generateSeed(RANDOM_LENGTH);
byte b[] = new byte[RANDOM_LENGTH];
random.setSeed(seed);
random.nextBytes(b);
}catch(Exception e) {
e.printStackTrace();
}
return b;
}
import java.security.*;
...
public final static String RANDOM_ALGORITHM = "SHA1PRNG";
public final static int RANDOM_LENGTH = 16;
...
public byte[] getRandom() {
try {
SecureRandom random = SecureRandom.getInstance(RANDOM_ALGORITHM);
byte seed[] = random.generateSeed(RANDOM_LENGTH);
byte b[] = new byte[RANDOM_LENGTH];
random.setSeed(seed);
random.nextBytes(b);
}catch(Exception e) {
e.printStackTrace();
}
return b;
}
import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
// CHANGE THIS VALUE DEPENDING ON WHAT YOU WANT
public static final int MESSAGE_LENGTH = 1024;
/**
* @param text
* Message to encrypt
* @param secret_key
* Secret Key
* @param crypt_spec
* Crypt algorithm like "AES" or "DES"
* @return Encrypted Byte Strings
*/
public byte[] encrypt(String text, byte[] secret_key, String crypt_spec)
throws InvalidKeyException, IllegalBlockSizeException, IOException,
BadPaddingException {
SecretKeySpec sKey = new SecretKeySpec(secret_key, crypt_spec);
byte[] secret = new byte[MESSAGE_LENGTH];
try {
Cipher cipher = Cipher.getInstance(crypt_spec);
cipher.init(Cipher.ENCRYPT_MODE, sKey);
secret = cipher.doFinal(text.getBytes());
} catch (Exception e) {
System.out.println(this.getClass().getName()
+ ".encrypt: Exception:");
e.printStackTrace();
}
return secret;
}
/**
* @param b
* Encypted Byte Message
* @param crypt_spec
* Crypt Algorithm like "AES" or "DES"
* @return Decrypted String
*/
public String decrypt(byte[] b, byte[] secret_key, String crypt_spec)
throws InvalidKeyException, IllegalBlockSizeException, IOException,
BadPaddingException {
SecretKeySpec sKey = new SecretKeySpec(secret_key, crypt_spec);
byte[] secret = new byte[MESSAGE_LENGTH];
try {
Cipher cipher = Cipher.getInstance(crypt_spec);
cipher.init(Cipher.DECRYPT_MODE, sKey);
secret = cipher.doFinal(b);
} catch (Exception e) {
System.out.println(this.getClass().getName()
+ ".decrypt: Exception:");
e.printStackTrace();
}
return new String(secret);
}
import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
// CHANGE THIS VALUE DEPENDING ON WHAT YOU WANT
public static final int MESSAGE_LENGTH = 1024;
/**
* @param text
* Message to encrypt
* @param secret_key
* Secret Key
* @param crypt_spec
* Crypt algorithm like "AES" or "DES"
* @return Encrypted Byte Strings
*/
public byte[] encrypt(String text, byte[] secret_key, String crypt_spec)
throws InvalidKeyException, IllegalBlockSizeException, IOException,
BadPaddingException {
SecretKeySpec sKey = new SecretKeySpec(secret_key, crypt_spec);
byte[] secret = new byte[MESSAGE_LENGTH];
try {
Cipher cipher = Cipher.getInstance(crypt_spec);
cipher.init(Cipher.ENCRYPT_MODE, sKey);
secret = cipher.doFinal(text.getBytes());
} catch (Exception e) {
System.out.println(this.getClass().getName()
+ ".encrypt: Exception:");
e.printStackTrace();
}
return secret;
}
/**
* @param b
* Encypted Byte Message
* @param crypt_spec
* Crypt Algorithm like "AES" or "DES"
* @return Decrypted String
*/
public String decrypt(byte[] b, byte[] secret_key, String crypt_spec)
throws InvalidKeyException, IllegalBlockSizeException, IOException,
BadPaddingException {
SecretKeySpec sKey = new SecretKeySpec(secret_key, crypt_spec);
byte[] secret = new byte[MESSAGE_LENGTH];
try {
Cipher cipher = Cipher.getInstance(crypt_spec);
cipher.init(Cipher.DECRYPT_MODE, sKey);
secret = cipher.doFinal(b);
} catch (Exception e) {
System.out.println(this.getClass().getName()
+ ".decrypt: Exception:");
e.printStackTrace();
}
return new String(secret);
}
String protocol = "http";
String hostname = "yourdomain.com";
int port = 80;
String file = "/";
try {
URL url = new URL(protocol, hostname, port, file);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true); // Input OK
conn.setDoOutput(true); // Output OK
conn.setUseCaches(false); // Cache NG
conn.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
conn.connect(); // Connect
boolean isRedirect = HttpURLConnection.getFollowRedirects();
String cookieValue = null;
try {
Map<String, List<String>> headers = conn.getHeaderFields();
List<String> values = headers.get("Set-Cookie");
for (Iterator<String> iter = values.iterator(); iter.hasNext();) {
String v = iter.next();
if (cookieValue == null)
cookieValue = v;
else
cookieValue = cookieValue + ";" + v;
}
} catch (Exception e) {
}
System.out.println(this.getClass().getName()
+ ": cookieValue: " + cookieValue);
conn.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
String protocol = "http";
String hostname = "yourdomain.com";
int port = 80;
String file = "/";
try {
URL url = new URL(protocol, hostname, port, file);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true); // Input OK
conn.setDoOutput(true); // Output OK
conn.setUseCaches(false); // Cache NG
conn.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
conn.connect(); // Connect
boolean isRedirect = HttpURLConnection.getFollowRedirects();
String cookieValue = null;
try {
Map<String, List<String>> headers = conn.getHeaderFields();
List<String> values = headers.get("Set-Cookie");
for (Iterator<String> iter = values.iterator(); iter.hasNext();) {
String v = iter.next();
if (cookieValue == null)
cookieValue = v;
else
cookieValue = cookieValue + ";" + v;
}
} catch (Exception e) {
}
System.out.println(this.getClass().getName()
+ ": cookieValue: " + cookieValue);
conn.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}